|
|

楼主 |
发表于 2023-3-31 19:37
|
显示全部楼层
源码
- <style>
- #papa {
- margin: auto;
- width: 1024px;
- height: 640px;
- background: lightblue url('https://638183.freep.cn/638183/t23/webp/lan.webp') center/cover no-repeat;
- box-shadow: 3px 3px 20px #000;
- position: relative;
- z-index: 1;
- }
- .donut {
- --delay: 0s; --tt: 8s;
- position: absolute;
- width: 30px;
- height: 40px;
- border-radius: 50%;
- border: 40px solid tan;
- border-width: 20px 30px 30px 20px;
- box-shadow: 0 0 12px #000 inset;
- opacity: .72;
- cursor: pointer;
- animation: rot var(--tt) var(--delay) infinite alternate linear var(--state);
- }
- @keyframes rot { to { transform: scale(1.5) rotate(2turn); } }
- </style>
- <div id="papa"></div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1957787337" autoplay loop></audio>
- <script>
- let spans = [];
- (function() {
- Array.from({length: 6}).forEach((item,key) => {
- let sp = document.createElement('span'), xx = Math.random()*30 + 30;
- sp.className = 'donut';
- sp.style.cssText += `
- left: ${Math.random()*(papa.offsetWidth-180) + 30}px;
- top: ${Math.random()*(papa.offsetHeight-180) + 30}px;
- border-color: #${Math.random().toString(16).substr(-6)} #${Math.random().toString(16).substr(-6)} #${Math.random().toString(16).substr(-6)} #${Math.random().toString(16).substr(-6)};
- width: ${xx}px;
- height: ${xx}px;
- --delay: ${Math.random()*key*.2}s;
- --tt: ${Math.random()*key +6}s;
- `;
- papa.appendChild(sp);
- spans.push(sp);
- });
- })();
- let mState = () => papa.style.setProperty('--state', aud.paused ? 'paused' : 'running');
- spans.forEach((item) => item.onclick = () => aud.paused ? aud.play() : aud.pause());
- aud.addEventListener('play', mState, false);
- aud.addEventListener('pause', mState, false);
- </script>
复制代码
|
|