|
|

楼主 |
发表于 2023-7-1 19:20
|
显示全部楼层
代码
- <style>
- #mydiv {
- margin: 0 0 0 calc(50% - 593px);
- width: 1024px;
- height: 600px;
- background: linear-gradient(to right top, rgba(100,0,0,.65), rgba(0,0,0,.7));
- overflow: hidden;
- position: relative;
- --state: paused;
- }
- #mplayer {
- position: absolute;
- left: 50%;
- bottom: 2px;
- transform: translate(-40%) rotate(90deg);
- font: normal 80px / 80px sans-serif;
- cursor: pointer;
- z-index: 999;
- }
- li-zi {
- display: block;
- position: absolute;
- left: 50%;
- bottom: 80px;
- width: 20px;
- height: 20px;
- background: snow;
- border-radius: 50%;
- animation: move 10s var(--delay) infinite ease-out var(--state);
- --deg: 30deg; --xx: -200px; --delay: 0;
- }
- @keyframes move {
- from { transform: rotate(0deg) translateY(0px); opacity: 1; }
- to { transform: rotate(var(--deg)) translateY(var(--xx)); opacity: 0; }
- }
- </style>
- <div id="mydiv">
- <div id="mplayer">🐟</div>
- </div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=144998" autoplay="autoplay" loop="loop"></audio>
- <script>
- (function (){
- let total = 30;
- let createLizi = (mum,sons) => {
- Array.from({length: sons}).forEach( (s,k) => {
- let xx = 6 + Math.ceil(Math.random() * 20);
- s = document.createElement('li-zi');
- s.style.cssText += `
- width: ${xx}px;
- height: ${xx}px;
- left: calc(50% - ${xx / 2}px);
- --deg: ${50 - Math.ceil(Math.random() * 100)}deg;
- --xx: -${300 + Math.ceil(Math.random() * 600)}px;
- --delay: -${Math.random() * 9}s;
- `;
- mum.appendChild(s);
- });
- };
- createLizi(mydiv,total);
- let mState = () => aud.paused ? (mydiv.style.setProperty('--state','paused'),canMove = false) : (mydiv.style.setProperty('--state','running'),canMove = true);
- aud.addEventListener('play', mState, false);
- aud.addEventListener('pause', mState, false);
- mplayer.onclick = () => aud.paused ? aud.play() : aud.pause();
- })();
- </script>
复制代码
|
|