2024年10月12日 星期六
<style>
#tz { margin: 20px auto; width: 600px; height: 900px; border: 1px solid gray; background: url('https://638183.freep.cn/638183/t24/4/hgti.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% - 100px); top: 20px; 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=35729475" 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[Math.floor(Math.random() * colors.length)],
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>
|