|
|

楼主 |
发表于 2022-8-28 07:04
|
显示全部楼层
代码分享(全)
- <style>
- #papa { margin: auto; width: 1024px; height: 640px; background: gray url('/data/attachment/forum/202208/28/070015bjs2jahfnpaffay0.jpg') no-repeat center/cover;box-shadow: 3px 3px 20px #000; position: relative; z-index: 1; }
- #player { padding: 10px; position: absolute; left: 20px; bottom: 20px; width: fit-content; height: fit-content; display: flex; gap: 10px; flex-direction: column; }
- #lrctext { font: bold 1.4em sans-serif; color: silver; text-shadow: 1px 1px 2px #000; user-select: none; transition: all 1.5s; }
- #btnwrap { width: fit-content; height: fit-content; display: flex; gap: 8px; align-items: center; }
- #btnmain { width: 36px; height: 36px; display: grid; place-items: center; background: rgba(0,0,0,.5); border-radius: 50%; cursor: pointer; transition: all 2s; }
- #btnmain:hover { background: orange; }
- #btnplay { width: 16px; height: 16px; background: #ccc; 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; }
- #prgline { width: 200px; height: 4px; background: #ccc linear-gradient(to right,red,orange,green,red) no-repeat center left; background-size: 1px 4px; cursor: pointer; }
- #tmsg { font: normal 16px sans-serif; color: orange; user-select: none; text-shadow: 1px 1px 1px #000; transition: 1.5s; }
- #tmsg:hover, #lrctext:hover { color: tomato; }
- </style>
- <div id="papa">
- <div id="player">
- <div id="lrctext">lrc歌词</div>
- <div id="btnwrap">
- <span id="btnmain"><span id="btnplay"></span><span id="btnpause"></span></span>
- <span id="prgline"></span><span id="tmsg">00:00 | 00:00</span>
- </div>
- </div>
- </div>
- <script>
- let lrcAr = [
- ['00.00', '纯音乐 - 慵懒的猫'],
- ['170.00','感谢欣赏']
- ];
- let aud = new Audio();
- aud.src = 'https://music.163.com/song/media/outer/url?id=1413361244.mp3';
- aud.autoplay = true;
- aud.loop = true;
- btnmain.onclick = () => aud.paused ? aud.play() : aud.pause();
- prgline.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / prgline.offsetWidth;
- aud.addEventListener('pause', () => btnstate());
- aud.addEventListener('play',() => btnstate());
- aud.addEventListener('timeupdate', () => {
- prgline.style.backgroundSize = prgline.offsetWidth * aud.currentTime / aud.duration + 'px 4px';
- tmsg.innerText = toMin(aud.duration) + ' | ' + toMin(aud.currentTime);
- for(j=0; j<lrcAr.length; j++) {
- if(aud.currentTime >= lrcAr[j][0]) lrctext.innerText = lrcAr[j][1];
- }
- });
- let btnstate = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none') : (btnplay.style.display = 'none', btnpause.style.display = 'block');
- 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>
复制代码
|
|