帖子代码
<style>
#tz { margin: 30px 0 30px calc(50% - 593px); width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/t24/4/earth.jpg') no-repeat center/cover; overflow: hidden; box-shadow: 0 0 6px #111; z-index: 1; position: relative; }
#player { position: absolute; cursor: pointer; fill: none; stroke: green; stroke-width: 4; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; }
li-zi { position: absolute; width: 10px; height: 6px; offset-path: path('M100 100Q200 800,1024 360'); offset-distance: 0%; background: green; animation: moving 10s linear infinite var(--state); }
@keyframes moving { to { offset-distance: 100%; } }
</style>
<div id="tz">
<!-- Earth -->
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=18649290" autoplay loop></audio>
<svg id="player" width="200" height="200" viewBox="-100 -100 200 200">
<ellipse cx="0" cy="0" rx="80" ry="60" fill="none" stroke-width="4" stroke="green" stroke-dasharray="4 8"></ellipse>
<polygon points="0 -50, 50 50, -50 50" pathLength="1">
<animate id="b1" attributeName="stroke-dashoffset" from="1" to="0" dur="2s" begin="0s;e1.end+.5s" fill="freeze"/>
<animate id="e1" attributeName="stroke-dashoffset" from="0" to="1" dur="2s" begin="e2.end" fill="freeze"/>
</polygon>
<circle cx="0" cy="0" r="50" pathLength="1">
<animate id="b2" attributeName="stroke-dashoffset" from="1" to="0" dur="2s" begin="b1.end" fill="freeze"/>
<animate id="e2" attributeName="stroke-dashoffset" from="0" to="1" dur="2s" begin="e3.end" fill="freeze"/>
</circle>
<rect x="-50" y="-50" width="100" height="100" pathLength="1" transform="rotate(45)">
<animate id="b3" attributeName="stroke-dashoffset" from="1" to="0" dur="2s" begin="b2.end" fill="freeze"/>
<animate id="e3" attributeName="stroke-dashoffset" from="0" to="1" dur="2s" begin="b3.end+1s" fill="freeze"/>
</rect>
</svg>
</div>
<script>
Array(total=40).fill(0).forEach((lz,key) => {
lz = document.createElement('li-zi');
lz.style.cssText += `animation-delay: -${10 / total * key}s`;
if(key % 2 === 0) lz.style.offsetPath = `path('M100 100Q800 -150,1024 360')`;
tz.appendChild(lz);
console.log(lz);
});
mState = () => aud.paused ? (tz.style.setProperty('--state', 'paused'), player.pauseAnimations()) : (tz.style.setProperty('--state', 'running'), player.unpauseAnimations());
aud.onplaying = aud.onpause = () => mState();
player.onclick = () => aud.paused ? aud.play() : aud.pause();
</script>
|