|
|

楼主 |
发表于 2022-10-26 07:24
|
显示全部楼层
代码
- <style>
- #papa { margin: auto; width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/t22/webp/goose.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; }
- #papa::before { position: absolute; content: url('https://638183.freep.cn/638183/t22/gif/girl.gif'); width: 160px; height: 60px; mix-blend-mode: multiply; }
- #mplayer { position: absolute; bottom: 10px; display: grid; grid-template-columns: auto auto auto; place-items: center; gap: 6px; user-select: none; }
- #btnplay {border-radius: 50%; width: 50px; height: 50px; cursor: pointer; animation: rot linear 3s 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, red); opacity: .65; }
- #audtime { font: normal 14px sans-serif; color: hsl(0,80%,50%); }
- #lrc { --motion: cover1; --tt: 5s; --state: paused; position: absolute; bottom: 60px; 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(60,50%,50%,.45),hsla(0,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">
- <img id="btnplay" src="https://638183.freep.cn/638183/t22/btn/g1.png" alt="" />
- <span id="prog"></span>
- <span id="audtime">00:00 | 00:00</span>
- </div>
- </div>
- <script>
- (function() {
- let aud = new Audio(), mKey = 0, mFlag = true, down = true;
- let lrcAr = [[0.06,"鹅(苏二零 )",18.3],[18.37,"词曲 : 苏二零 编曲 : 钟磊 制作人 : 谢炜岚",5.9],[24.32,"寺庙下有个池塘",2.2],[26.78,"白鹅嘎嘎嘎嘎叫声响",2.6],[30.18,"远处走来个少年郎",2.3],[32.91,"十七八岁的模样",2.3],[36.24,"他瞥见桥下有一姑娘",2.4],[38.93,"发间别着一朵红海棠",2.8],[42.03,"踌躇转身又跌跌撞撞",2.6],[44.86,"衣角却漏了慌张",2.8],[48.3,"鹅鹅鹅曲项向天歌",2.5],[50.98,"谁家少年又动心了",2.8],[54.17,"鹅鹅鹅曲项向天歌",2.5],[57,"姑娘笑颜如花着",2.8],[60.06,"鹅鹅鹅曲项向天歌",2.8],[63.24,"恼它们唱的什么歌",2.6],[66.18,"鹅鹅鹅曲项向天歌",2.6],[68.9,"笑那少年他到底该如何",3.6],[86.21,"寺庙下有个池塘",1.9],[88.38,"白鹅嘎嘎嘎嘎叫声响",2.6],[91.68,"远处走来个少年郎",2.5],[94.52,"十七八岁的模样",2.3],[97.85,"他瞥见桥下有一姑娘",2.3],[100.39,"发间别着一朵红海棠",2.8],[103.79,"踌躇转身又跌跌撞撞",2.4],[106.42,"衣角却漏了慌张",2.8],[109.83,"鹅鹅鹅曲项向天歌",2.4],[112.47,"谁家少年又动心了",2.8],[115.68,"鹅鹅鹅曲项向天歌",2.6],[118.5,"姑娘笑颜如花着",2.6],[121.78,"鹅鹅鹅曲项向天歌",2.5],[124.71,"恼它们唱的什么歌",2.5],[127.7,"鹅鹅鹅曲项向天歌",2.5],[130.39,"笑那少年他到底该如何",2.8],[135.34,"鹅鹅鹅曲项向天歌",2.3],[138.21,"谁家少年又动心了",2.8],[141.25,"鹅鹅鹅曲项向天歌",2.6],[143.81,"姑娘笑颜如花着",3.1],[147.29,"鹅鹅鹅曲项向天歌",2.4],[150.27,"恼它们唱的什么歌",2.6],[153.27,"鹅鹅鹅曲项向天歌",2.4],[155.89,"笑那少年他到底该如何",3.4]];
- aud.src = 'https://music.163.com/song/media/outer/url?id=1930158632.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>
复制代码
|
|