帖子代码
<style>
#papa { margin: 20px 0 0 calc(50% - 593px); width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/t24/webp/green.webp') no-repeat center/cover; box-shadow: 3px 3px 6px gray; overflow: hidden; z-index: 1; position: relative; --left: 50px; }
#btnplay { position: absolute; top: 10px; left: 0; width: 100px; transition: left 6s; cursor: pointer; animation: rot 8s linear infinite var(--state); }
li-zi { position: absolute; left: var(--left); top: 55px; width: 2px; height: 2px; background: lightgreen; box-shadow: 0 -4px 6px green; transition: left 6s; }
@keyframes moving { to { transform: translate(var(--x0),var(--y0)); opacity: 0; } }
@keyframes rot { to { transform: rotate(360deg); } }
</style>
<div id="papa">
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=1440425602" autoplay loop></audio>
<img id="btnplay" src="https://638183.freep.cn/638183/web/svg/flower_3.svg" alt="" title="点击播放" />
</div>
<script>
(function() {
let all = 300;
for(let i = 0; i < all; i++) { let lz = document.createElement('li-zi'); let hudu = Math.PI / 180 * 360 / all * i; let xx = 200 * Math.cos(hudu), yy = 200 * Math.sin(hudu); lz.style.cssText += ` --x0: ${xx}px; --y0: ${yy}px; animation: moving ${Math.random() + .5}s linear -${Math.random()}s infinite var(--state); `; papa.prepend(lz); }
let sF = document.createElement('script');
sF.src = 'https://638183.freep.cn/638183/web/api/fullscreen.js';
sF.charset = 'utf-8';
document.querySelector('body').appendChild(sF);
sF.onload = () => FS({papa: '#papa', css: '--bg: transparent; --color: #eee; bottom: 10px; left: 48%;'});
let mState = () => aud.paused ? (papa.style.setProperty('--state','paused'),btnplay.title = '点击播放') : (papa.style.setProperty('--state','running'),btnplay.title = '点击暂停');
let getOffsetPos = (ele) => { let x = ele.offsetLeft, y = ele.offsetTop, pa = ele.offsetParent; while(pa != null) { x += pa.offsetLeft; y += pa.offsetTop; pa = pa.offsetParent; } return {x, y}; };
let movTimer = null, paWidth = papa.clientWidth, sonSize = btnplay.clientWidth, bodyWidth = document.body.clientWidth, paOffset = getOffsetPos(papa).x;
document.onmousemove = function(e) { clearTimeout(movTimer); movTimer = setTimeout(function() { if (e.target.id === "btnplay" || e.target.id == 'btnFs') return; if (document.fullscreenElement === null) { let x = e.pageX; if (x < paOffset) x = paOffset; x = x - paOffset; if (x + sonSize >= paWidth) x = paWidth - sonSize; btnplay.style.cssText += `left: ${x}px`; papa.style.setProperty('--left', `${x + 40}px`); } else { let xx = e.offsetX || e.layerX; if (xx + sonSize > bodyWidth) xx -= sonSize; btnplay.style.cssText += `left: ${xx}px;`; papa.style.setProperty('--left', `${xx + 40}px`); } }, 400); };
aud.onpause = aud.onplaying = () => mState();
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
})();
</script>
|