【寂静之声】学习黑师星空倒影月亮播放效果
<style>#papa {
--state: paused;
margin: -80px 0 0 calc(50% - 649px);
width: 1136px;
height: 640px;
background: lightblue url('https://pic.imgdb.cn/item/6402de9af144a010073a1f36.jpg') no-repeat center/cover;
box-shadow: 6px 3px 20px #DDA0DD;
overflow: hidden;
position: relative;
z-index: 1;
}
.moon {
position: absolute;
width: 100px;
height: 100px;
left: calc(50% - 50px);
cursor: crosshair;
z-index: 999;
}
.moon::before, .moon::after {
position: absolute;
content: '';
border-radius: 50%;
}
.moon::before {
width: 80px;
height: 80px;
background: transparent;
box-shadow: 20px 10px 0 Khaki;
animation: swing linear 2s infinite alternate var(--state);
}
.moon::after {
background: Khaki;
width: 30px;
height: 30px;
left: 35px;
top: 35px;
}
.reflect {
bottom: 20px;
filter: blur(1.2px) opacity(.15);
transform: rotateX(-180deg);
}
.star {
position: absolute;
background: lightblue;
box-shadow: 0 0 2px white inset;
opacity: 0;
filter: blur(.5px);
display: block;
}
#btnFs {
position: absolute;
left: 20px;
bottom: 20px;
width: fit-content;
height: fit-content;
padding: 6px;
border-radius: 6px;
border: 2px solid snow;
color: snow;
display: none;
cursor: crosshair;
}
@keyframes swing { to { transform: rotate(45deg); } }
@keyframes flash { to { transform: rotate(45deg); opacity: .6; } }</style><div id="papa"><div class="moon"></div><div class="moon reflect"></div><div id="btnFs">全屏观赏</div><audio id="aud" src="https://music.163.com/song/media/outer/url?id=1300029572.mp3" autoplay="" loop=""></audio></div><script>(function() {
let moons = document.querySelectorAll('.moon'), fs = false, timerId;
for(let j = 0; j < 600; j ++) {
let star = document.createElement('span'), size = Math.ceil(Math.random() * 4);
star.className = 'star';
star.style.cssText += `
left: ${Math.random() * 100}%;
top: ${Math.random() * 50}%;
width: ${size}px;
height: ${size}px;
animation: flash 1s ${Math.random() * 20}s infinite alternate var(--state);
`;
papa.appendChild(star);
}
let mState = () => papa.style.setProperty('--state', aud.paused ? 'paused' : 'running');
moons.forEach((item) => item.onclick = () => aud.paused ? aud.play() : aud.pause());
aud.addEventListener('play', () => mState());
aud.addEventListener('pause', () => mState());
aud.addEventListener('ended', () => playNext());
aud.addEventListener('error', () => {
if(aud.error.code === 4) aud.src = 'http://www.kumeiwp.com/sub/filestores/2023/02/26/f8e9ca01f8ae47d00c2fb150b30cee48.mp3';
});
papa.addEventListener('mousemove', (e) => {
clearTimeout(timerId);
btnFs.style.display = 'block';
timerId = setTimeout('btnFs.style.display = "none"', 3000);
});
btnFs.addEventListener('click', () => fs ? document.exitFullscreen() : papa.requestFullscreen());
document.addEventListener('fullscreenchange', () => document.fullscreenElement !== null ? (fs = true, btnFs.innerText = '退出全屏') : (fs = false, btnFs.innerText = '全屏观赏'));
})();</script> @马黑黑 交份作业 {:4_199:}{:4_199:} 悄然的这个制作有意思,鼠标移动到播放器上变成了十字光标,不是习惯的手型光标呢{:4_187:} 天上一月亮,水里一个月亮,满天的星星,还有星光下的美人。悄然的制作真美{:4_199:} 看到悄然回来特别开心{:4_173:} 好帖子
歌听了十多年? 100√ 意境悠远,点赞。 天上的月亮和地上的呼应,真美啊!{:4_204:} 天上月亮,地上美人,仰望星空,思念远人。做的真好! 几天没见到悄然了很挂念呢。{:4_187:} 悄然的作业做得漂亮,创意美美哒,问好哦{:4_187:} 辫子哥哥 发表于 2023-3-4 15:50
{:4_187:}感谢版版鼓励 红影 发表于 2023-3-4 15:52
悄然的这个制作有意思,鼠标移动到播放器上变成了十字光标,不是习惯的手型光标呢
{:4_204:}不会换别的,换个鼠标形。最后发现还是手形的好看 红影 发表于 2023-3-4 15:53
天上一月亮,水里一个月亮,满天的星星,还有星光下的美人。悄然的制作真美
描红描红,不会自己整,抄的作业{:4_187:} 红影 发表于 2023-3-4 15:55
看到悄然回来特别开心
{:4_183:}抱一个喽 马黑黑 发表于 2023-3-4 16:13
好帖子
歌听了十多年?
顺手捞到,老是这些个,怪事{:4_187:} 马黑黑 发表于 2023-3-4 16:19
100√
满意了{:4_199:}谢老师