|
|

楼主 |
发表于 2023-12-10 22:19
|
显示全部楼层
帖子代码
- <style>
- #papa { margin: 0 0 0 calc(50% - 593px); width: 1024px; height: 640px; background: #666 url('https://638183.freep.cn/638183/t23/webp2/ybli.webp') no-repeat center/cover; overflow: hidden; display: grid; place-items: center; box-shadow: 3px 6px 12px gray; position: relative; --state: paused; }
- #player { width: 300px; cursor: pointer; animation: rotating 18s linear infinite var(--state); }
- mov-ball { position: absolute; width: 20px; height: 20px; border-radius: 50%; background: tan; animation: imov 6s infinite; }
- @keyframes moving {
- from { opacity: 0; transform: translate(0,0); }
- to { opacity: 1; transform: translate(var(--x0),var(--y0)); }
- }
- @keyframes rotating { to { transform: rotate(360deg); } }
- </style>
- <div id="papa">
- <img id="player" src="https://638183.freep.cn/638183/web/svg/sunfl-1.svg" alt="" title="" />
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1996509752" autoplay loop></audio>
- </div>
- <script>
- (function() {
- let all = 100;
- for(let i = 0; i < all; i++) {
- let movBall = document.createElement('mov-ball');
- let hudu = Math.PI / 180 * 360 / all * i;
- let xx = 600 * Math.cos(hudu), yy = 600 * Math.sin(hudu);
- movBall.style.cssText += `
- --x0: ${xx}px;
- --y0: ${yy}px;
- background: #${Math.random().toString(16).substr(-6)};
- animation: moving ${Math.random() * 20 + 20}s -${Math.random() * 20}s infinite var(--state);
- `;
- papa.prepend(movBall);
- }
- let playMusic = () => aud.paused ? (aud.play(), player.title='暂停') : (aud.pause(), player.title='播放');
- let mState = () => papa.style.setProperty('--state', aud.paused ? 'paused' : 'running');
- aud.addEventListener('playing',mState,false);
- aud.addEventListener('pause',mState,false);
- player.addEventListener('click',playMusic,false);
- })();
- </script>
复制代码
|
评分
-
查看全部评分
|