|
|

楼主 |
发表于 2022-9-22 07:45
|
显示全部楼层
本帖完整代码(本地测试模式):
- <style>
- #papa { margin: auto; width: 1024px; height: 640px; background: url('./pic/bjehp.webp') no-repeat center/cover; box-shadow: 3px 3px 20px #000; box-shadow: 3px 3px 20px #000; display: flex; justify-content: center; overflow: hidden; position: relative; z-index: 1; }
- #mplayer { position: absolute; bottom: 4px; width: 240px; height: 80px; user-select: none; 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, snow, darkgreen); opacity: 1; }
- #btnwrap, #prog { position: absolute; display: grid; place-items: center; transition: .5s; }
- #btnwrap { --yy: -15px; width: 40px; height: 40px; border-radius: 50%; border: 4px solid lightgreen; opacity: 0.1;}
- #btnplay { width: 20px; height: 20px; 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: 240px; height: 18px; border-radius: 10px; background: linear-gradient(90deg, rgba(0,0,0,.45), rgba(255,0,0,.75) 100%, transparent 0); border: 1px solid lightgreen; font: normal 14px/18px sans-serif; color: snow; }
- #lrc { position: absolute; top: 10px; font: bold 2.4em sans-serif; color: transparent; background: linear-gradient(-90deg, darkgreen, transparent) 0 0 / 200% 200%; filter: drop-shadow(2px 2px 4px #000); background-clip: text; -webkit-background-clip: text; text-stroke: 1px lightgreen; -webkit-text-stroke: 1px lightgreen; }
- @keyframes bgMove1 { from { background-position: 0 0; } to { background-position: -100% 0; } }
- @keyframes bgMove2 { from { background-position: 0 0; } to { background-position: -100% 0; } }
- </style>
- <div id="papa">
- <div id="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 lrcAr = [
- [0,"词 | 曲 | 演唱: 李健",46.5],
- [47.8,"在我的怀里 在你的眼里",6.3],
- [55.78,"那里春风沉醉 那里绿草如茵",6.3],
- [63.85,"月光把爱恋 洒满了湖面",6.4],
- [71.8,"两个人的篝火 照亮整个夜晚",5.7],
- [78.01,"多少年以后 如云般游走",6.0],
- [85.8,"那变换的脚步 让我们难牵手",6.2],
- [93.54,"这一生一世 有多少你我",6.9],
- [101.74,"被吞没在月光如水的夜里",7.2],
- [113.9,"多想某一天 往日又重现",6.2],
- [121.75,"我们流连忘返 在贝加尔湖畔",6.6],
- [162,"多少年以后 往事随云走",6.6],
- [169.72,"那纷飞的冰雪容不下那温柔",6.7],
- [177.77,"这一生一世 这时间太少",7.4],
- [185.75,"不够证明融化冰雪的深情",7.7],
- [197.81,"就在某一天 你忽然出现",6.0],
- [205.91,"你清澈又神秘 在贝加尔湖畔",6.2],
- [213.02,"你清澈又神秘 像贝加尔湖畔",7.8]
- ];
- let mKey = 0, mFlag = true, aud = new Audio();
- prog.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth;
- aud.src = 'http://www.kumeiwp.com/sub/filestores/2022/03/29/357d900bcae5a1788c32ac7df6c0d20d.mp3';
- aud.autoplay = true;
- aud.loop = true;
- btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
- aud.addEventListener('pause', () => mState());
- aud.addEventListener('play', () => mState());
- aud.addEventListener('seeked', () => calcKey());
- aud.addEventListener('timeupdate', () => {
- prog.style.background= 'linear-gradient(90deg, rgba(0,0,0,.45), rgba(255,0,0,.75) ' + aud.currentTime / aud.duration * 100 + '%, transparent 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.animationPlayState = 'paused') : (btnplay.style.display = 'none', btnpause.style.display = 'block', lrc.style.animationPlayState = 'running');
- let showLrc = (time) => {
- lrc.style.animation = (mFlag ? 'bgMove1 ' : 'bgMove2 ') + time + 's linear forwards';
- lrc.innerHTML = lrcAr[mKey][1];
- 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 mtime = lrcAr[mKey][2] - (aud.currentTime - lrcAr[mKey][0]);
- showLrc(mtime);
- }
- 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>
复制代码
|
|