|
|

楼主 |
发表于 2022-9-17 19:30
|
显示全部楼层
本帖最后由 马黑黑 于 2022-9-17 20:41 编辑
代码分享
- <style>
- #papa { left: -214px; width: 1024px; height: 640px; background: #ccc url('/data/attachment/forum/202209/17/192354ds48umk8khro44u4.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; overflow: hidden; position: relative; z-index: 1; }
- #mplayer { position: absolute; bottom: 0; width: 300px; 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, 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; 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, blue 100%, transparent 0); border: 1px solid gray; font: normal 14px / 16px sans-serif; color: olive; opacity: .75; }
- #lrc { position: absolute; right: 20px; top: 20px; font: bold 2em sans-serif; color: transparent; letter-spacing: 2px; background: linear-gradient(-90deg, purple, orange) 100% 100% / 200% 200%; background-clip: text; -webkit-background-clip: text; }
- #plane {position: absolute;left: 60px;top: 0;width: 100px;offset-distance: 0;offset-path: path("M0 20 Q300 80, 600 200 T1000 100");animation: move 8s linear infinite;}
- @keyframes bgMove1 { from { background-position: 0 0; } to { background-position: -100% 0; } }
- @keyframes bgMove2 { from { background-position: 0 0; } to { background-position: -100% 0; } }
- @keyframes move { to { offset-distance: 100%;} }
- </style>
- <div id="papa">
- <img id="plane" src="/data/attachment/forum/202209/17/192324pvmm0vvrnsds3yhd.png" alt="" />
- <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.01, '关淑怡 - 忘记他', 1],
- [1.03, '作词:黄沾', 0],
- [2.03, '作曲:黄沾', 16],
- [18.05, '忘记他', 4],
- [22.07, '等于忘掉了一切', 5],
- [27.09, '等于将方和向抛掉', 4],
- [32.07, '遗失了自己', 4],
- [37.06, '忘记他', 4],
- [41.10, '等于忘尽了欢喜', 4],
- [46.05, '等于将心灵也锁住', 5],
- [51.08, '同苦痛一起', 5],
- [56.09, '从来只有他', 4],
- [61.08, '可以令我欣赏自己', 4],
- [66.04, '更能让我去用爱', 3],
- [69.06, '将一切平凡事', 2],
- [72.03, '变得美丽', 4],
- [77.01, '忘记他', 4],
- [81.04, '怎么忘记得起', 5],
- [86.06, '铭心刻骨来永久记住', 3],
- [91.03, '从此永无尽期', 6],
- [107.05, 'Ba', 18],
- [125.05, '忘记他', 4],
- [129.06, '等于忘掉了欢喜', 5],
- [134.06, '等于将心灵也锁住', 4],
- [139.04, '同苦痛一起', 5],
- [144.06, '从来只有他', 4],
- [149.05, '可以令我欣赏自己', 4],
- [154.00, '更能让我去用爱', 3],
- [157.04, '将一切平凡事', 2],
- [160.01, '变得美丽', 3],
- [165.00, '忘记他', 4],
- [169.02, '怎么忘记得起', 4],
- [174.03, '铭心刻骨来永久记住', 4.5],
- [179.01, '从此永无尽期', 6],
- ];
- let mKey = 0, mFlag = true;
- let aud = new Audio();
- aud.src = 'https://music.163.com/song/media/outer/url?id=68288.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, blue ' + 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.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;
- 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>
复制代码
|
|