<!DOCTYPE html>
<html>
<head>
    <title>放烟花</title>
    <style>
        body {
            background-color: black;
        }
<pre><code>    #firework {
        position: relative;
        width: 100%;
        height: 100%;
    }
    
    .firework-dot {
        position: absolute;
        width: 10px;
        height: 10px;
        background-color: red;
        border-radius: 50%;
    }
&lt;/style&gt;
</code></pre>
</head>
<body>
    <div id="firework"></div>
<pre><code>&lt;script&gt;
    function createFirework() {
        var firework = document.getElementById(&quot;firework&quot;);
        var dot = document.createElement(&quot;div&quot;);
        dot.className = &quot;firework-dot&quot;;
        dot.style.top = Math.random() * 100 + &quot;%&quot;;
        dot.style.left = Math.random() * 100 + &quot;%&quot;;
        dot.style.animationDuration = Math.random() * 2 + 1 + &quot;s&quot;;
        firework.appendChild(dot);

        setTimeout(function() {
            firework.removeChild(dot);
        }, 3000);
    }

    setInterval(createFirework, 500);
&lt;/script&gt;
</code></pre>
</body>
</html

原文地址: https://www.cveoy.top/t/topic/hUiB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录