|
|

楼主 |
发表于 2022-9-27 07:33
|
显示全部楼层
代码(本地测试模式)
- <style>
- #papa { margin: auto; width: 1024px; height: 640px; background: #ccc url('https://638183.freep.cn/638183/Pic/81/57.webp') no-repeat center/cover; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; user-select: none; position: relative; z-index: 1; }
- #mplayer { position: absolute; bottom: 0; left: 20px; width: 300px; height: 80px; display: grid; place-items: center; cursor: pointer; }
- #mplayer:hover #btnwrap, #mplayer:hover #prog { transform: translateY(var(--yy)); }
- #mplayer:hover #btnwrap { background: linear-gradient(to top right, red, green); border-radius: 50%; opacity: .75; }
- #btnwrap, #prog { position: absolute; display: grid; place-items: center; transition: .5s; }
- #btnwrap { --yy: -15px; width: 40px; height: 40px; transform: rotate(45deg); border: 1px solid tan; border-radius: 6px; opacity: .25; }
- #btnplay { width: 20px; height: 20px; transform: translateX(3px); background: #eee; clip-path: polygon(0 0, 0% 100%, 100% 50%); }
- #btnpause { width: 2px; height: 20px; border-style: solid; border-width: 0px 4px; border-color: transparent #eee; display: none; }
- #prog { --yy: 20px; width: 300px; height: 16px; border-radius: 10px; background: linear-gradient(90deg, black, red 100%, transparent 0); border: 1px solid gray; font: normal 14px / 16px sans-serif; color: snow; text-shadow: 1px 1px 0 #111; opacity: .75; }
- #lrc { position: absolute; top: 10px; font: bold 2.6em sans-serif; color: rgba(255,255,255,.95); text-shadow: 1px 1px 1px #000; --motion: cover2; --tt: 1s; --state: running; }
- #lrc::before { position: absolute; content: attr(data-lrc); width: 0; height: 100%; left: 0; top: 0; color: rgba(210,60,20,.8); overflow: hidden; white-space: nowrap; animation: var(--motion) var(--tt) linear forwards; animation-play-state: var(--state); }
- #mpic { position: absolute; left: 0; width: 300px; mix-blend-mode: multiply; }
- @keyframes cover1 { from { width: 0; } to { width: 100%; } }
- @keyframes cover2 { from { width: 0; } to { width: 100%; } }
- </style>
- <div id="papa">
- <img id="mpic" src="https://638183.freep.cn/638183/Pic/81/tree.jpg" alt="" />
- <div id="lrc" data-lrc="花潮论坛lrc在线">花潮论坛lrc在线</div>
- <div id="mplayer">
- <div id="btnwrap"><span id="btnplay"></span><span id="btnpause"></span></div>
- <div id="prog">00:00 | 00:00</div>
- </div>
- </div>
- <script>
- let mKey = 0, mFlag = true, aud = new Audio();
- let lrcAr = [[1.0,"归去来兮 | 词曲唱 : 花粥",14.0],[15.18,"余音袅袅我看了太多热闹",3.0],[18.14,"看一尘不染的白纸都变得浮躁",3.0],[21.45,"善者寥寥在泥沼之中煎熬",3.1],[24.59,"而置身事外的君子在一旁冷笑",3.1],[27.99,"没完没了的暗箭持续叫嚣",3.1],[31.12,"怕没人注意到他们得意着作妖",3.3],[34.38,"纷纷扰扰这人间缺个公道",3.2],[37.58,"我辞三界 别五行自顾去逍遥",3.3],[41.08,"此去必经年 荒野寒暑换红颜",6.3],[47.33,"往事散云烟 十寸光阴换一钱",6.5],[53.8,"只身山水间 耳不闻恶语闲言",6.5],[60.26,"举头问苍天 何时得以赴黄泉",7.2],[93.2,"走走停停又逛了几个世纪",2.8],[96.02,"看川流不息灯红酒绿变成孤寂",3.1],[99.36,"战战兢兢的人们未曾怀疑",3.1],[102.44,"在此地荣华富贵是唯一的真理",3.1],[105.78,"机关算尽后徒留一地黄金",3.2],[108.97,"那冢里枯骨不得安息无人在意",3.1],[112.29,"夜色降临时落下一声叹息",3.1],[115.39,"我乘兴来 败兴去也乐得随意",3.1],[131.92,"此去必经年 荒野寒暑换红颜",6.3],[138.19,"往事散云烟 十寸光阴换一钱",6.5],[144.72,"只身山水间 耳不闻恶语闲言",6.4],[151.14,"举头问苍天 何时得以赴黄泉",6.7],[157.88,"此去必经年 荒野寒暑换红颜",6.5],[164.37,"往事散云烟 十寸光阴换一钱",6.3],[170.76,"只身山水间 耳不闻恶语闲言",6.5],[177.21,"举头问苍天 何时得以赴黄泉",6]];
- aud.src = 'https://music.163.com/song/media/outer/url?id=1357999894.mp3';
- aud.autoplay = true;
- aud.loop = true;
- btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
- prog.onclick = (e) => 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.background= 'linear-gradient(90deg, black, red ' + aud.currentTime / aud.duration * 100 + '%, snow 0)';
- prog.innerText = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);
- for(j=0; j<lrcAr.length; j++) {
- if(aud.currentTime >= lrcAr[j][0]) {
- if(mKey === j) showLrc(lrcAr[j][2]);
- else continue;
- }
- }
- });
- let mState = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none', lrc.style.setProperty('--state', 'paused')) : (btnplay.style.display = 'none', btnpause.style.display = 'block', lrc.style.setProperty('--state', 'running'));
- 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 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 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>
复制代码
|
|