本帖最后由 马黑黑 于 2024-3-9 12:03 编辑
帖子代码
<style>
#papa { margin: 0 0 0 calc(50% - 593px); width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/t24/1/redmaple.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; overflow: hidden; z-index: 1; position: relative; }
#btnplay { position: absolute; width: 100px; left: 0; top: 10px; opacity: .7; transition: 6s; cursor: pointer; animation: rot 8s linear infinite var(--state); }
#vid { position: absolute; top: -130px; left: -150px; width: 400px; height: 400px; object-fit: cover; border-radius: 30%; opacity: .5; transition: 6s; mix-blend-mode: screen; pointer-events: none; }
@keyframes rot { to { transform: rotate(360deg); } }
</style>
<div id="papa">
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=1447306956" autoplay loop></audio>
<video id="vid" src="https://img.tukuppt.com/video_show/2629112/00/02/10/5b5145bb2514a.mp4" loop></video>
<img id="btnplay" src="https://638183.freep.cn/638183/small/sunny.png" alt="" />
</div>
<script>
(function() {
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 = '点击播放',vid.pause()) : (papa.style.setProperty('--state','running'),btnplay.title = '点击暂停',vid.play());
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}; };
aud.onplaying = aud.onpause = () => mState();
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
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") 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;`; vid.style.cssText += `left: ${x - 150}px;`; } else { let xx = e.offsetX || e.layerX; if (xx + sonSize > bodyWidth) xx -= sonSize; btnplay.style.cssText += `left: ${xx}px;`; vid.style.cssText += `left: ${xx - 150}px;`; } }, 400);
};
})();
</script>
|