朵拉 发表于 2024-10-12 23:54

千 年(学习马黑黑和光同尘效果)

本帖最后由 朵拉 于 2024-10-27 23:07 编辑 <br /><br /><style>
        #tz { margin: 20px auto; width: 600px; height: 900px; border: 1px solid gray; background: url('https://pic.imgdb.cn/item/670a9916d29ded1a8c11919e.jpg') no-repeat center/cover; box-shadow: 3px 3px 6px gray; border-radius: 8px; z-index: 1; position: relative; }
        #player, #ssvg { position: absolute; }
        #player { width: 200px; height: 200px; left: calc(50% - 1px); top: 490px; cursor: pointer; animation: rot 8s infinite linear var(--state); }
        .down { animation: down var(--dur) var(--delay) linear infinite var(--state), flash 1s var(--delay) infinite alternate linear var(--state); }
        @keyframes down { to { transform: rotate(-10deg) translate(0, 1000px); } }
        @keyframes flash { to { opacity: 0; } }
        @keyframes rot { to { transform: rotate(360deg); } }
</style>

<div id="tz">
        <audio id="aud" src="https://music.163.com/song/media/outer/url?id=2619953379" autoplay loop></audio>
        <svg id="ssvg" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
                <symbol id="cc" width="10" height="10" viewBox="0 0 10 10">
                        <circle cx="5" cy="5" r="5"></circlie>
                </symbol>
                <defs>
                        <g><animate attributeName="y" to="400" dur="10s" repeatCount="indefinite"></animate></g>
                </defs>
        </svg>
        <img id="player" alt="" src="https://638183.freep.cn/638183/web/svg/3star_133731353409967500.svg" />
</div>

<script>
mkBalls = (num) => {
        var ww = ssvg.clientWidth,
                str = '',
                colors = ['orange', 'tan', 'yellow', 'gold', 'red', 'plum', 'pink', 'purple'];
        Array(num).fill(0).forEach((a,b) => {
                var x = Math.round(Math.random() * (ww - 20)),
                        size = Math.floor(Math.random() * 6) + 6,
                        fill = colors,
                        dur = Math.floor(10 * Math.random() + 10),
                        delay = -1 * Math.round(Math.random() * 15);
                str += `<use x="${x}" y="-20" width="${size}" height="${size}" fill="${fill}" href="#cc" class="down" style="--dur:${dur}s;--delay:${delay}s"/>`;
        });
        return str;
};

ssvg.innerHTML += mkBalls(50);

mState = () => {
        player.style.setProperty('--state', aud.paused ? 'paused' : 'running');
        ssvg.style.setProperty('--state', aud.paused ? 'paused' : 'running');
};
aud.onplaying = aud.onpause = () => mState();
player.onclick = () => aud.paused ? aud.play() : aud.pause();
</script>

朵拉 发表于 2024-10-12 23:55

@马黑黑
老师 晚上好,学生交作业,请指正哈{:4_190:}

梦江南 发表于 2024-10-13 07:28

欣赏老师佳作,早上好!{:4_199:}

马黑黑 发表于 2024-10-13 08:08

{:4_199:}

红影 发表于 2024-10-13 09:03

漂亮,欣赏朵宝好帖{:4_204:}

梦油 发表于 2024-10-13 09:12

欣赏佳作,问候朵拉。
页: [1]
查看完整版本: 千 年(学习马黑黑和光同尘效果)