<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>点击烟花波纹效果</title>
<style>
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
cursor: pointer;
background-color: #121212;
font-family: Arial, sans-serif;
}
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.6);
transform: scale(0);
pointer-events: none;
animation: ripple 1s ease-out;
}
.particle {
position: absolute;
border-radius: 50%;
pointer-events: none;
animation: particle 1s ease-out forwards;
}
@keyframes ripple {
to {
transform: scale(3);
opacity: 0;
}
}
@keyframes particle {
0% {
transform: translate(0, 0);
opacity: 1;
}
100% {
transform: translate(var(--tx), var(--ty));
opacity: 0;
}
}
.footer {
position: fixed;
bottom: 15px;
width: 100%;
text-align: center;
color: rgba(255, 255, 255, 0.7);
font-size: 14px;
z-index: 100;
}
.footer a {
color: #ff9800;
text-decoration: none;
transition: color 0.3s;
}
.footer a:hover {
color: #ff5722;
text-decoration: underline;
}
</style>
</head>
<body>
<script>
document.addEventListener('click', function(e) {
createRipple(e.clientX, e.clientY);
createParticles(e.clientX, e.clientY); // 修复了函数名拼写错误
});
function createRipple(x, y) {
const ripple = document.createElement('div');
ripple.className = 'ripple';
// 随机颜色
const hue = Math.floor(Math.random() * 360);
ripple.style.background = `hsla(${hue}, 100%, 70%, 0.6)`;
ripple.style.left = (x - 20) + 'px';
ripple.style.top = (y - 20) + 'px';
ripple.style.width = '40px';
ripple.style.height = '40px';
document.body.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 1000);
}
function createParticles(x, y) { // 修复了函数名拼写错误
const particleCount = 30;
const angleIncrement = (Math.PI * 2) / particleCount;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
// 随机大小
const size = Math.random() * 8 + 4;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
// 随机颜色
const hue = (Math.floor(Math.random() * 60) + (i % 2 === 0 ? 0 : 180));
particle.style.background = `hsl(${hue}, 100%, 70%)`;
// 计算粒子运动方向
const angle = angleIncrement * i;
const distance = Math.random() * 100 + 50;
const tx = Math.cos(angle) * distance;
const ty = Math.sin(angle) * distance;
particle.style.setProperty('--tx', `${tx}px`);
particle.style.setProperty('--ty', `${ty}px`);
particle.style.left = (x - size/2) + 'px';
particle.style.top = (y - size/2) + 'px';
document.body.appendChild(particle);
setTimeout(() => {
particle.remove();
}, 1000);
}
}
</script>
</body>
</html>
720

被折叠的 条评论
为什么被折叠?



