|
|

楼主 |
发表于 2022-9-11 20:22
|
显示全部楼层
代码:
- <style>
- #papa { margin: auto; width: 1024px; height: 640px; background: transparent; display: grid; place-items: center;box-shadow: 3px 3px 20px #000; 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, green); }
- #btnwrap, #prog { position: absolute; display: grid; place-items: center;transition: .5s; }
- #btnwrap { --yy: -15px; width: 40px; height: 40px; border-radius: 50%; border: 4px solid pink; }
- #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: 20px; border-radius: 10px; background: linear-gradient(90deg, rgba(255,0,0,.45), rgba(0,255,0,.35) 70%, transparent 0); border: 1px solid pink; font: normal 14px sans-serif; color: purple; }
- #s_svg { position: absolute; width: 400px; height: 50px;left: 0px; top: 10px; animation: move 12s linear infinite alternate;}
- #lrc { text-anchor: middle; dominant-baseline: middle; font: bold 2em sans-serif; fill: none; stroke: red; }
- @keyframes move { to {left: 624px;} }
- </style>
- <div id="papa">
- <div id="mplayer">
- <div id="btnwrap"><span id="btnplay"></span><span id="btnpause"></span></div>
- <div id="prog">00:00 | 00:00</div>
- </div>
- <svg id="s_svg"><text id="lrc" x="50%" y="50%">lrc歌词</text></svg>
- </div>
- <script>
- let lrcAr = [
- ['0.00','月亮啊月亮'],
- ['180.00','感谢支持']
- ];
- let aud = new Audio();
- aud.src = 'http://www.kumeiwp.com/sub/filestores/2022/08/29/4ff9b3d04e7ae8f20d90a52cefb99595.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', () => btnstate());
- aud.addEventListener('play',() => btnstate());
- aud.addEventListener('timeupdate', () => {
- prog.style.background= 'linear-gradient(90deg, rgba(255,0,0,.45), rgba(0,255,0,.35) ' + aud.currentTime / aud.duration * 100 + '%, transparent 0)';//prog.offsetWidth * aud.currentTime / aud.duration) + 'px 0px';
- prog.innerText = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);
- for(j=0; j<lrcAr.length; j++) {
- if(aud.currentTime >= lrcAr[j][0]) lrc.textContent = 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>
复制代码
|
|