亦是金 发表于 2023-12-11 20:41

涂鸦冬雨的学习马老师 【逃脱引力 】效果帖



<style>
#papa {
       margin: auto;
       width: 1036px;
       height: 698px;
       top:50px;
       left: -310px;
       background: #666 url('https://pic.imgdb.cn/item/6575f7a2c458853aef1d63f1.jpg') no-repeat center/cover;
       overflow: hidden;
       display: grid;
       place-items: center;
       box-shadow: 3px 6px 12px gray;
       position: relative;
       --state: paused;
}
#player { width: 70px;cursor: pointer; margin-top:250px; margin-left: 0px; animation: rotating 8s linear infinite var(--state); }
mov-ball { position: absolute; width: 20px; height: 20px;margin-top:250px; margin-left: 0px; border-radius: 50%; background: tan; animation: imov 6s infinite; }
@keyframes moving {
                from { opacity: 0; transform: translate(0,0); }
                to { opacity: .3; transform: translate(var(--x0),var(--y0)); }
      }
@keyframes rotating { to { transform: rotate(-360deg); } }
</style>

<div id="papa">
      <img id="player" src="https://pic.imgdb.cn/item/6575f443c458853aef133d55.gif" alt="" title="" />
      <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1374860954" autoplay loop></audio>
</div>

<script>

(function() {

let all = 50;
for(let i = 0; i < all; i++) {
      let movBall = document.createElement('mov-ball');
      let hudu = Math.PI / 100 * 360 / all * i;
      let xx = 150 * Math.cos(hudu), yy = 80 * 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>

红影 发表于 2023-12-11 21:09

这个是调整了xx和yy的值么,有趣{:4_173:}
页: [1]
查看完整版本: 涂鸦冬雨的学习马老师 【逃脱引力 】效果帖