<!-- 第一部分 :css代码 -->
<style>
/* 帖子容器id选择器 */
#mydiv {
position: relative;
margin: 30px 0 30px calc(50% - 931px);
width: 1700px;
height: 900px;
background: url('https://642303.freep.cn/642303/tu/20240728di800202.webp') no-repeat center/cover;
overflow: hidden;
}
/* 小播class选择器 */
.player {
position: absolute;
bottom: 40px;
width: 120px;
height: 120px;
opacity: .99;
cursor: pointer;
animation: rot 8s linear infinite var(--state);
}
.player:nth-of-type(4) { width: 70px;height: 70px;right: 450px;bottom:360px; } /* 对标的 img 标签排在帖子中第3位 */
.player:nth-of-type(5) {border-radius: 50%;width: 50px;height: 50px;left: 296px; bottom:580px; } /* 对标的 img 标签排在帖子中第4位 */
/* 飞鹰图片选择器 */
.bird {
position: absolute;
right: -100px;
bottom: 10px;
width: 120px;
height: 120px;
opacity: .3;
animation: fly 16s linear infinite var(--state);
}
.bird:nth-of-type(2) { bottom: 110px;width: 160px;height: 160px;animation-delay: -10s; } /* 对标的 img 标签排在帖子中第2位 :提前2秒执行动画 */
.bird:nth-of-type(3) { bottom: 310px;width: 140px;height: 140px;animation-delay: -14s; } /* 对标的 img 标签排在帖子中第3位 :提前4秒执行动画 */
/* 视频class选择器 */
.vid {
position: absolute;
width: 100%;
height:110%;
object-fit: cover;
pointer-events: none;
opacity: 1;
}
.vid:nth-of-type(1) { top:-80px;mix-blend-mode: screen;border-radius: 50%;width: 80%;height:60%; right:-350px;opacity: 0.99; top:430px;} /* 对标的 video 标签排在帖子中第1位 */
.vid:nth-of-type(2) { width: 16%;height:16%; opacity: 0.96; mix-blend-mode: screen;top:510px;left:150px;-webkit-mask: radial-gradient(circle, silver, lightgreen, cyan, transparent,transparent);} /* 对标的 video 标签排在帖子中第2位 */
@keyframes rot { to { transform: rotate(360deg); } }
@keyframes fly { to { right: 1600px; } }
</style>
<!-- 第二部分 :html代码 父元素带9个子元素 -->
<div id="mydiv">
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=1483504366" autoplay loop></audio>
<video class="vid" src="https://img.tukuppt.com/video_show/2629112/00/02/24/5b5866d92b5c4.mp4" autoplay loop muted></video>
<video class="vid" src="https://img.tukuppt.com/video_show/2418175/00/18/94/5ef7acd140037.mp4" autoplay loop muted></video>
<img class="bird" alt="" src="https://642303.freep.cn/642303/za/pngsucai_2614287_2df54e.png" />
<img class="bird" alt="" src="https://642303.freep.cn/642303/za/pngsucai_2614287_2df54e.png" />
<img class="bird" alt="" src="https://642303.freep.cn/642303/za/pngsucai_2614287_2df54e.png" />
<img class="player" alt="" src="https://pic.imgdb.cn/item/64a28a991ddac507ccde4215.png" title="播放/暂停" />
<img class="player" alt="" src="https://pic.imgdb.cn/item/64a28a071ddac507ccdd3b30.png" title="播放/暂停" />
</div>
<!-- 第三部分 :JS代码 -->
<script>
//声明并获取待控制的元素集合变量 : vids 视频、players 小播、birds 图片飞鹰
var vids = mydiv.querySelectorAll('.vid'),
players = mydiv.querySelectorAll('.player'),
birds = mydiv.querySelectorAll('.bird');
//联动控制函数
var mState = () => {
mydiv.style.setProperty('--state', aud.paused ? 'paused' : 'running');
vids.forEach(vid => aud.paused ? vid.pause() : vid.play());
players.forEach(player => player.title = aud.paused ? '播放' : '暂停');
};
//audio空间三个监听事件
aud.oncanplay = aud.onplaying = aud.onpause = () => mState();
//小播点击事件
players.forEach(player => player.onclick = () => aud.paused ? aud.play() : aud.pause());
</script>
|