帖子代码
<style>
#papa { margin: 0 0 0 calc(50% - 593px); width: 1024px; height: 640px; background: navy; box-shadow: 3px 3px 20px #000; overflow: hidden; position: relative; z-index: 1; }
#papa::before , #papa::after { position: absolute; content: ''; left: var(--begin1); top: 0px; width: 100%; height: 100%; background: url('https://638183.freep.cn/638183/t24/jpg/yzxl.jpg') no-repeat center/cover; z-index: -1; }
#papa::after { left: var(--begin2); transform: scale(-1,1); }
#play { position: absolute; right: 70px; top: 120px; width: 100px; mix-blend-mode: multiply; cursor: pointer; animation: rotating 5s linear infinite var(--state); }
#vid { position: absolute; width: calc(100% + 160px); height: 100%; object-fit: cover; mix-blend-mode: screen; pointer-events: none; }
@keyframes rotating { to { transform: rotate(360deg); } }
</style>
<div id="papa">
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=2045451899" autoplay></audio>
<video id="vid" src="https://img.tukuppt.com/video_show/2422006/00/02/13/5b51af9e299f9.mp4" autoplay muted loop></video>
<img id="play" src="https://638183.freep.cn/638183/small/f01.png" alt="" />
</div>
<script>
var ww = papa.offsetWidth;
var step = 0.2, begin1 = 0, begin2 = ww, raf;
aud.loop = false;
aud.onpause = aud.onplaying = () => moving();
aud.onseeked = () => cancelAnimationFrame(raf);
aud.onended = () => { cancelAnimationFrame(raf); aud.play(); };
play.onclick = () => { aud.paused ? aud.play() : aud.pause(); };
var moving = () => {
begin1 += step;
begin2 += step;
if(begin1 >= ww) begin1 = -ww;
if(begin2 >= ww) begin2 = -ww;
let b2 = begin2 + (begin1 >= 0 ? 1 : -1);
papa.style.setProperty('--begin1', begin1 + 'px');
papa.style.setProperty('--begin2', b2 + 'px');
aud.paused
? (cancelAnimationFrame(raf), papa.style.setProperty('--state', 'paused'), vid.pause())
: (raf = requestAnimationFrame(moving), papa.style.setProperty('--state', 'running'),vid.play());
};
</script>
|