福宝 发表于 2024-6-28 21:43

江月初照人


<style>
#mydiv { --width: 1024px; margin: 30px 0 30px calc(50% - (var(--width) / 2 + 90px)); width: var(--width); height: 640px; background: #eee url('https://gd-hbimg.huaban.com/6dafa90d1ecab6168ae595035e593137f65c8bdfb1064-wsO4tr') no-repeattop 0px center/cover; box-shadow: 2px 2px 8px rgba(0,0,0,.7); overflow: hidden; z-index: 1; position: relative;}

.ball {
position: absolute;
content:url('https://gd-hbimg.huaban.com/02cc7ba22b581e519ad6645e30d35613277adef4d3a9-0ShNcZ');
width: 140px; height: 140px;
/*background: linear-gradient(plum, teal)*/;
border-radius: 50%;
opacity: .95; transition: width .5s, height .5s, opacity .5s;
cursor: pointer; offset-path: path('M40 20 Q512 1080,984 20');
offset-distance: 0; animation: 6s linear forwards;
}
.ball:hover { width: 150px; height: 150px; opacity: .75; }

.ball:nth-of-type(1) {
left: -40px; top: 0;
animation-name: move1-1;}

.ball:nth-of-type(2) {
left: 40px; top: 0;
/*background: linear-gradient(tan, cyan); */
offset-distance: 50%;}

#vid { position: absolute; width: 80%; height: 50%; transform: scale(-1,1) rotate(30deg); object-fit: cover; mix-blend-mode: multiply; pointer-events: none; }
@keyframes move1-1 {
    from { offset-distance: 0%; transform: rotate(720deg); filter: hue-rotate(0); }
    to { offset-distance: 50%; transform: rotate(0); filter: hue-rotate(360deg); }
}
@keyframes move1-2 {
    from { offset-distance: 50%; transform: rotate(0); filter: hue-rotate(360deg); }
    to { offset-distance: 0%; transform: rotate(720deg); filter: hue-rotate(0); }
}
@keyframes move2-1 {
    from { offset-distance: 50%; transform: rotate(720deg); filter: hue-rotate(0deg); }
    to { offset-distance: 100%; transform: rotate(0); filter: hue-rotate(360deg); }
}
@keyframes move2-2 {
    from { offset-distance: 100%; transform: rotate(0); filter: hue-rotate(360deg); }
    to { offset-distance: 50%; transform: rotate(720deg); filter: hue-rotate(0); }
}
</style>

<div id="mydiv">
    <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1345498593" autoplay loop></audio>
    <video id="vid" src="https://img.tukuppt.com/video_show/2269348/00/17/44/5ec494a494d82.mp4" autoplay loop muted></video>
    <div id="b1" class="ball"></div>
    <div id="b2" class="ball"></div>
</div>

<script>
//小球数组
const balls = ;
//小球1动画结束
b1.onanimationend = ()=> {
    let ani = window.getComputedStyle(b1).getPropertyValue('animation-name');
    if(ani === 'move1-1') {
      b1.style.animationName = '';
      b2.style.animationName = 'move2-1';
    }else{
      b1.style.animationName = 'move1-1';
    }
};
//小球2动画结束
b2.onanimationend = () => {
    let ani = window.getComputedStyle(b2).getPropertyValue('animation-name');
    if(ani === 'move2-1') {
      b2.style.animationName = 'move2-2';
    }else{
      b2.style.animationName = '';
      b1.style.animationName = 'move1-2';
    }
};
//联动控制函数
var mState = () => {
    balls.forEach(b => {
      b.style.animationPlayState = aud.paused ? 'paused' : 'running';
      b.title = ['暂停','播放'][+aud.paused];
    });
    aud.paused ? vid.pause() : vid.play();
};
//音频控件监听事件
aud.oncanplay = aud.onplaying = aud.onpause = () => mState();
//小球点击事件
balls.forEach(b => b.onclick = () => aud.paused ? aud.play() : aud.pause());
//加载全屏插件
var 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: '#mydiv',
    css: 'bottom: 10px; left: 50%; transform: translate(-50%); --color: snow; --fsBg: transparent;',
});
//动画响应窗体变化
window.onresize = () => balls.forEach(b => {
    b.style.offsetPath = `path('M40 20 Q${mydiv.offsetWidth / 2} ${mydiv.offsetHeight * 2 - 200}, ${mydiv.offsetWidth - 40} 20')`;
    b.style.animationDuration = ((mydiv.offsetWidth + mydiv.offsetHeight) / (1024 + 640)) * 6 + 's';
});
</script>

蜻蜓 发表于 2024-6-28 22:39

那小球好玩
页: [1]
查看完整版本: 江月初照人