马黑黑 发表于 2022-10-13 07:35

飞天

<style>
#papa { left: -214px; width: 1024px; height: 640px; background: snow url('https://638183.freep.cn/638183/t22/webp/fwtm.webp') no-repeat center/cover; display: grid; place-items: center; box-shadow: 3px 3px 20px #000; user-select: none; position: relative; }
#mplayer { position: absolute; bottom: 5px; width: 400px; height: 60px; font: normal 14px sans-serif; }
#mplayer::before, #mplayer::after { position: absolute; width: 100%; height: 50%; color: snow; margin: 15px 0; }
#mplayer::before { content: attr(data-cur); }
#mplayer::after { content: attr(data-dur); text-align: right; }
#btnplay { position: absolute; left: calc(50% - 15px); bottom: 25px; width: 30px; height: 30px; border-radius: 50%; background: conic-gradient(red, magenta, blue, aqua, lime, yellow, red); cursor: pointer; z-index: 2; animation: rot linear 4s infinite; }
#prog { --posX: 0px; position: absolute; bottom: 10px; width: 100%; height: 1px; background: #eee; cursor: pointer; }
#prog::before, #prog::after { position: absolute; content: ''; left: 0; }
#prog::before { width: var(--posX); height: 1px; background: red; }
#prog::after { left: var(--posX); top: calc(50% - 6px); width: 10px; height: 10px; border-radius: 50%; background: pink; }
#lrc { --motion: cover1; --tt: 5s; --state: paused; position: absolute; bottom: 80px; font: bold 2.4em sans-serif; color: hsl(0,10%,90%); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px hsla(0,100%,0%,.85)); }
#lrc::before { position: absolute; content: attr(data-lrc); width: 20%; height: 100%; color: transparent; overflow: hidden; white-space: nowrap; background: linear-gradient(180deg,hsla(28,15%,50%,.75),hsla(28,100%,50%,.75)); filter: inherit; -webkit-background-clip: text; animation: var(--motion) var(--tt) linear forwards; animation-play-state: var(--state); }
@keyframes cover1 { from { width: 0; } to { width: 100%; } }
@keyframes cover2 { from { width: 0; } to { width: 100%; } }
@keyframes rot { to { transform: rotate(1turn); } }
</style>

<div id="papa">
        <div id="lrc" data-lrc="花潮lrc在线">花潮lrc在线</div>
        <div id="mplayer" data-cur="00:00" data-dur="00:00"><span id="prog"></span><span id="btnplay"></span></div>
</div>

<script>
let mKey = 0, mFlag = true, aud = new Audio();
let lrcAr = [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,];
aud.src = 'http://www.kumeiwp.com/sub/filestores/2021/03/17/02d99f4ec6fb3170e3ab54d24dfda321.mp3';
aud.autoplay = true;
aud.loop = true;
if(aud.paused) btnplay.style.animationPlayState = 'paused';
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
mplayer.onmousemove = (e) => { mplayer.style.cursor = e.offsetY > mplayer.offsetHeight / 1.5 ? 'pointer' : 'default'; }
mplayer.onclick =(e) => { if(e.offsetY > mplayer.offsetHeight / 1.5) aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth; }
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());
aud.addEventListener('timeupdate', () => { prog.style.setProperty('--posX', prog.offsetWidth * aud.currentTime / aud.duration + 'px'); mplayer.dataset.cur = toMin(aud.currentTime); mplayer.dataset.dur = toMin(aud.duration); for(j=0; j<lrcAr.length; j++) {if(aud.currentTime >= lrcAr) {if(mKey === j) showLrc(lrcAr);else continue;} } });
let mState = () => aud.paused ? (btnplay.style.animationPlayState = 'paused', lrc.style.setProperty('--state', 'paused')) : (btnplay.style.animationPlayState ='running', lrc.style.setProperty('--state', 'running'));
let showLrc = (time) => {let name = mFlag ? 'cover1' : 'cover2';lrc.innerHTML = lrc.dataset.lrc = lrcAr;lrc.style.setProperty('--motion', name);lrc.style.setProperty('--tt', time + 's');lrc.style.setProperty('--state', 'running');mKey += 1;mFlag = !mFlag;};
let calcKey = () => {for(j = 0; j < lrcAr.length; j ++) {if(aud.currentTime <= lrcAr) {mKey = j - 1;break;}}if(mKey <0) mKey = 0;if(mKey > lrcAr.length - 1) mKey = lrcAr.length - 1;let time = lrcAr - (aud.currentTime - lrcAr);showLrc(time);};
let toMin = (val) => { if (!val) return '00:00'; val = Math.floor(val); let min = parseInt(val / 60), sec = parseFloat(val % 60); if(min < 10) min = '0' + min; if(sec < 10) sec = '0' + sec; return min + ':' + sec; };
papa.oncontextmenu = () => false;
</script>

马黑黑 发表于 2022-10-13 07:35

完整代码
<style>
#papa { left: -214px; width: 1024px; height: 640px; background: snow url('https://638183.freep.cn/638183/t22/webp/fwtm.webp') no-repeat center/cover; display: grid; place-items: center; box-shadow: 3px 3px 20px #000; user-select: none; position: relative; }
#mplayer { position: absolute; bottom: 5px; width: 400px; height: 60px; font: normal 14px sans-serif; }
#mplayer::before, #mplayer::after { position: absolute; width: 100%; height: 50%; color: snow; margin: 15px 0; }
#mplayer::before { content: attr(data-cur); }
#mplayer::after { content: attr(data-dur); text-align: right; }
#btnplay { position: absolute; left: calc(50% - 15px); bottom: 25px; width: 30px; height: 30px; border-radius: 50%; background: conic-gradient(red, magenta, blue, aqua, lime, yellow, red); cursor: pointer; z-index: 2; animation: rot linear 4s infinite; }
#prog { --posX: 0px; position: absolute; bottom: 10px; width: 100%; height: 1px; background: #eee; cursor: pointer; }
#prog::before, #prog::after { position: absolute; content: ''; left: 0; }
#prog::before { width: var(--posX); height: 1px; background: red; }
#prog::after { left: var(--posX); top: calc(50% - 6px); width: 10px; height: 10px; border-radius: 50%; background: pink; }
#lrc { --motion: cover1; --tt: 5s; --state: paused; position: absolute; bottom: 80px; font: bold 2.4em sans-serif; color: hsl(0,10%,90%); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px hsla(0,100%,0%,.85)); }
#lrc::before { position: absolute; content: attr(data-lrc); width: 20%; height: 100%; color: transparent; overflow: hidden; white-space: nowrap; background: linear-gradient(180deg,hsla(28,15%,50%,.75),hsla(28,100%,50%,.75)); filter: inherit; -webkit-background-clip: text; animation: var(--motion) var(--tt) linear forwards; animation-play-state: var(--state); }
@keyframes cover1 { from { width: 0; } to { width: 100%; } }
@keyframes cover2 { from { width: 0; } to { width: 100%; } }
@keyframes rot { to { transform: rotate(1turn); } }
</style>

<div id="papa">
        <div id="lrc" data-lrc="花潮lrc在线">花潮lrc在线</div>
        <div id="mplayer" data-cur="00:00" data-dur="00:00"><span id="prog"></span><span id="btnplay"></span></div>
</div>

<script>
let mKey = 0, mFlag = true, aud = new Audio();
let lrcAr = [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,];
aud.src = 'http://www.kumeiwp.com/sub/filestores/2021/03/17/02d99f4ec6fb3170e3ab54d24dfda321.mp3';
aud.autoplay = true;
aud.loop = true;
if(aud.paused) btnplay.style.animationPlayState = 'paused';
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
mplayer.onmousemove = (e) => { mplayer.style.cursor = e.offsetY > mplayer.offsetHeight / 1.5 ? 'pointer' : 'default'; }
mplayer.onclick =(e) => { if(e.offsetY > mplayer.offsetHeight / 1.5) aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth; }
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());
aud.addEventListener('timeupdate', () => { prog.style.setProperty('--posX', prog.offsetWidth * aud.currentTime / aud.duration + 'px'); mplayer.dataset.cur = toMin(aud.currentTime); mplayer.dataset.dur = toMin(aud.duration); for(j=0; j<lrcAr.length; j++) {if(aud.currentTime >= lrcAr) {if(mKey === j) showLrc(lrcAr);else continue;} } });
let mState = () => aud.paused ? (btnplay.style.animationPlayState = 'paused', lrc.style.setProperty('--state', 'paused')) : (btnplay.style.animationPlayState ='running', lrc.style.setProperty('--state', 'running'));
let showLrc = (time) => {let name = mFlag ? 'cover1' : 'cover2';lrc.innerHTML = lrc.dataset.lrc = lrcAr;lrc.style.setProperty('--motion', name);lrc.style.setProperty('--tt', time + 's');lrc.style.setProperty('--state', 'running');mKey += 1;mFlag = !mFlag;};
let calcKey = () => {for(j = 0; j < lrcAr.length; j ++) {if(aud.currentTime <= lrcAr) {mKey = j - 1;break;}}if(mKey <0) mKey = 0;if(mKey > lrcAr.length - 1) mKey = lrcAr.length - 1;let time = lrcAr - (aud.currentTime - lrcAr);showLrc(time);};
let toMin = (val) => { if (!val) return '00:00'; val = Math.floor(val); let min = parseInt(val / 60), sec = parseFloat(val % 60); if(min < 10) min = '0' + min; if(sec < 10) sec = '0' + sec; return min + ':' + sec; };
papa.oncontextmenu = () => false;
</script>


马黑黑 发表于 2022-10-13 07:40

试一下昨天写好的线条+小光盘播放器。播放器的代码:

一、CSS

#mplayer { position: absolute; bottom: 5px; width: 400px; height: 60px; font: normal 14px sans-serif; }
#mplayer::before, #mplayer::after { position: absolute; width: 100%; height: 50%; color: snow; margin: 15px 0; }
#mplayer::before { content: attr(data-cur); }
#mplayer::after { content: attr(data-dur); text-align: right; }
#btnplay { position: absolute; left: calc(50% - 15px); bottom: 25px; width: 30px; height: 30px; border-radius: 50%; background: conic-gradient(red, magenta, blue, aqua, lime, yellow, red); cursor: pointer; z-index: 2; animation: rot linear 4s infinite; }
#prog { --posX: 0px; position: absolute; bottom: 10px; width: 100%; height: 1px; background: #eee; cursor: pointer; }
#prog::before, #prog::after { position: absolute; content: ''; left: 0; }
#prog::before { width: var(--posX); height: 1px; background: red; }
#prog::after { left: var(--posX); top: calc(50% - 6px); width: 10px; height: 10px; border-radius: 50%; background: pink; }
@keyframes rot { to { transform: rotate(1turn); } }

二、HTML

        <div id="mplayer" data-cur="00:00" data-dur="00:00"><span id="prog"></span><span id="btnplay"></span></div>

三、JS配套代码的改变

主要是两个地方:一是 mState 函数,二是aud对 timeupdate 的监听。

马黑黑 发表于 2022-10-13 07:45

线条+小光盘播放控制器,由 mplayer 包裹,父子元素共三个:

一是父元素 mplayer ,它的两个伪元素用于显示音乐的播放时间信息;

二是 btnplay 即小光盘,它因为要旋转,没有使用它的伪元素(如果用的话也只能做装饰用);

三是 prog 即进度条,白线是它自己,叠加其上的红线是伪元素,装饰用的粉色小小球也是伪元素。

播放器进度条可控。

红影 发表于 2022-10-13 09:15

哇,最喜欢的敦煌飞天壁画,太美了{:4_199:}

红影 发表于 2022-10-13 09:21

马黑黑 发表于 2022-10-13 07:40
试一下昨天写好的线条+小光盘播放器。播放器的代码:

一、CSS


黑黑又有新播放器,很赞{:4_199:}

红影 发表于 2022-10-13 09:25

马黑黑 发表于 2022-10-13 07:45
线条+小光盘播放控制器,由 mplayer 包裹,父子元素共三个:

一是父元素 mplayer ,它的两个伪元素用于 ...

其实这个粉色小球用小方块应该也挺好看,本来就代表滑块{:4_173:}

小九 发表于 2022-10-13 09:45

第一次听到这歌,非常好听{:4_199:}

梦油 发表于 2022-10-13 11:30

千娇百媚、美不胜收。

醉美水芙蓉 发表于 2022-10-13 11:51

马黑黑 发表于 2022-10-13 12:10

醉美水芙蓉 发表于 2022-10-13 11:51
好美的播放器!

感谢支持

马黑黑 发表于 2022-10-13 12:11

梦油 发表于 2022-10-13 11:30
千娇百媚、美不胜收。

佛界的宣传队{:4_170:}

马黑黑 发表于 2022-10-13 12:11

小九 发表于 2022-10-13 09:45
第一次听到这歌,非常好听

云朵的歌还是不错的

马黑黑 发表于 2022-10-13 12:12

红影 发表于 2022-10-13 09:15
哇,最喜欢的敦煌飞天壁画,太美了

佛界中的高端文艺队{:4_170:}

马黑黑 发表于 2022-10-13 12:12

红影 发表于 2022-10-13 09:21
黑黑又有新播放器,很赞

还行还行

马黑黑 发表于 2022-10-13 12:13

红影 发表于 2022-10-13 09:25
其实这个粉色小球用小方块应该也挺好看,本来就代表滑块

方也是可以的,它可以和小光盘配套,恰好可以构成天圆地方、天大地小的效果

红影 发表于 2022-10-13 13:20

马黑黑 发表于 2022-10-13 12:12
佛界中的高端文艺队

文艺队,哈哈,真敢说{:4_189:}

红影 发表于 2022-10-13 13:21

马黑黑 发表于 2022-10-13 12:12
还行还行

黑黑厉害,每天回复那么多,还能研究代码,太敏捷了{:4_187:}

红影 发表于 2022-10-13 13:22

马黑黑 发表于 2022-10-13 12:13
方也是可以的,它可以和小光盘配套,恰好可以构成天圆地方、天大地小的效果

我就是说说,现在这个也很漂亮{:4_187:}

梦油 发表于 2022-10-13 17:18

马黑黑 发表于 2022-10-13 12:11
佛界的宣传队

内行看门道,外行看热闹。{:4_189:}
页: [1] 2 3 4 5
查看完整版本: 飞天