0
点赞
收藏
分享

微信扫一扫

粒子动画效果

醉倾城1 2024-09-23 阅读 37

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Particle Animation</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            background-color: #282c34;
            overflow: hidden;
        }
        .particle {
            position: absolute;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.6);
            pointer-events: none;
        }
    </style>
</head>
<body>
    <script>
        function createParticle() {
            const particle = document.createElement('div');
            particle.className = 'particle';
            particle.style.width = `${Math.random() * 10 + 5}px`;
            particle.style.height = particle.style.width;
            particle.style.left = `${Math.random() * window.innerWidth}px`;
            particle.style.top = `${Math.random() * window.innerHeight}px`;
            document.body.appendChild(particle);

            setTimeout(() => {
                particle.style.transform = `translateY(${window.innerHeight}px)`;
                particle.style.opacity = '0';
            }, 0);

            setTimeout(() => {
                document.body.removeChild(particle);
            }, 2000);
        }

        setInterval(createParticle, 100);
    </script>
</body>
</html>

举报

相关推荐

0 条评论