|
|

楼主 |
发表于 2022-10-22 08:02
|
显示全部楼层
CSS+HTML播放器(文本符号按钮)+歌词同步。代码:
- <style>
- #papa { margin: auto; width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/t22/webp/401.webp') no-repeat center/cover; box-shadow: 3px 3px 20px #000; position: relative; display: grid; place-items: center; user-select: none; z-index: 1; --opt: .25; }
- #mplayer { position: absolute; bottom: 20px; display: grid; grid-template-columns: auto auto auto; place-items: center; gap: 6px; user-select: none; }
- #btnplay { width: 40px; height: 40px; text-align: center; font: normal 40px/40px sans-serif; color: snow; cursor: pointer; animation: rot linear 4s infinite; }
- #prog { --ww: 0px; width: 300px; height: 12px; border: 1px solid green; border-radius: 6px; background: snow; opacity: .65; position: relative; }
- #prog::before { position: absolute; content: ''; width: var(--ww); height: 12px; border-radius: 6px; background: snow linear-gradient(90deg, orange, green); opacity: .75; }
- #audtime { font: normal 14px sans-serif; color: snow; }
- #lrc { --motion: cover1; --tt: 5s; --state: paused; position: absolute; top: 30px; font: bold 2.4em sans-serif; color: hsl(0,10%,90%); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px hsla(0,0%,0%,.95)); }
- #lrc::before { position: absolute; content: attr(data-lrc); width: 20%; height: 100%; color: transparent; overflow: hidden; white-space: nowrap; background: linear-gradient(180deg,hsla(0,50%,20%,.45),hsla(140,100%,50%,.75)); filter: inherit; -webkit-background-clip: text; animation: var(--motion) var(--tt) linear forwards; animation-play-state: var(--state); }
- #fish { offset-path: path('M310 195a93.5 62 0 1 0 187 0a93.5 62 0 1 0 -187 0z'); offset-distance: 100%; animation: swim 50s infinite; }
- @keyframes cover1 { from { width: 0; } to { width: 100%; } }
- @keyframes cover2 { from { width: 0; } to { width: 100%; } }
- @keyframes rot { to { transform: rotate(1turn); } }
- @keyframes swim { to { offset-distance: 0%; } }
- </style>
- <div id="papa">
- <img id="fish" src="https://wj1.zp68.com:812/lxx/yunhua/2022/10/02/gnyu.jpg" alt="" />
- <div id="lrc" data-lrc="花潮lrc在线">花潮lrc在线</div>
- <div id="mplayer">
- <span id="btnplay">❁</span>
- <span id="prog"></span>
- <span id="audtime">00:00 | 00:00</span>
- </div>
- </div>
- <script>
- (function() {
- let aud = new Audio(), mKey = 0, mFlag = true;
- let lrcAr = [[0.12,"花 - 演唱 :花儿乐队",15],[17.87,"看着你飘动着迷人的身体",6.0],[26.48,"透出了像花一般的美丽",6.0],[34.88,"你想要那人世间的痴迷",6.0],[43.01,"并不在乎谁会把你丢弃",6.0],[52.02,"你有美丽的脸可根已经枯萎",5.6],[60.3,"我想要的泉水在心中粉碎",5.8],[68.36,"看着你回想起了我的过去",5.8],[76.81,"无意中发出了低声的叹息",5.8],[85.26,"没有雨天空依然很忧郁",6.0],[93.37,"但愿明天不会再这样继续",6.0],[102.4,"你有美丽的脸可根已经枯萎",5.6],[110.69,"我想要的泉水在心中粉碎",5.8],[152.15,"你有美丽的脸可根已经枯萎",5.6],[161.02,"我想要的泉水在心中粉碎",5.8],[168.87,"哎~~~",31.0]];
- aud.src = 'https://music.163.com/song/media/outer/url?id=357421.mp3';
- aud.loop = true;
- aud.autoplay = true;
- if(aud.paused) btnplay.style.animationPlayState = 'paused';
- btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
- prog.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth;
- aud.addEventListener('seeked', () => calcKey());
- aud.addEventListener('pause', () =>mState());
- aud.addEventListener('play', () =>mState());
- aud.addEventListener('timeupdate', () => {let prg = aud.currentTime * prog.offsetWidth / aud.duration < 6 ? 6 : aud.currentTime * prog.offsetWidth / aud.duration;prog.style.setProperty('--ww', prg + 'px');audtime.innerText = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);for(j=0; j<lrcAr.length; j++) {if(aud.currentTime >= lrcAr[j][0]) {cKey = j;if(mKey === j) showLrc(lrcAr[j][2]);else continue;}}});
- let calcKey = () => {for(j = 0; j < lrcAr.length; j ++) {if(aud.currentTime <= lrcAr[j][0]) {mKey = j - 1;break;}}if(mKey <0) mKey = 0;if(mKey > lrcAr.length - 1) mKey = lrcAr.length - 1;let time = lrcAr[mKey][2] - (aud.currentTime - lrcAr[mKey][0]);showLrc(time);};
- let showLrc = (time) => {let name = mFlag ? 'cover1' : 'cover2';lrc.innerHTML = lrc.dataset.lrc = lrcAr[mKey][1];lrc.style.setProperty('--motion', name);lrc.style.setProperty('--tt', time + 's');lrc.style.setProperty('--state', 'running');mKey += 1;mFlag = !mFlag;};
- let mState = () => aud.paused ? (btnplay.style.animationPlayState='paused',lrc.style.setProperty('--state', 'paused'),papa.style.setProperty('--opt','0')) : (btnplay.style.animationPlayState='running', lrc.style.setProperty('--state', 'running'),papa.style.setProperty('--opt','.25'));
- 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;}
- })();
- </script>
复制代码
|
|