|
|

楼主 |
发表于 2023-7-23 08:32
|
显示全部楼层
本帖测试新制作的细线进度条播放器,不做特效装饰:
- <style>
- #papa { margin: 0 0 0 calc(50% - 593px); width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/t23/webp1/vmlm.webp') no-repeat center/cover; box-shadow: 3px 3px 20px #000; position: relative; z-index: 1; display: grid; place-items: center; }
- #prog { position: absolute; bottom: 20px; width: 280px; height: 12px; background: linear-gradient(to right, snow var(--prg), gray 0) repeat-x 0 50% / 100% 1px; color: snow; display: grid; place-items: center; --prg: 0%; --state: paused; }
- #prog::before, #prog::after { position: absolute; top: -30px; }
- #prog::before { content: attr(data-cu); left: 0; }
- #prog::after { right: 0; content: attr(data-du); }
- #slider { position: absolute; width: 3px; height: 7px; background: snow; left: var(--prg); }
- #btnplay { position: absolute; top: -50px; width: 38px; height: 38px; background: url('https://638183.freep.cn/638183/t23/btn/flowers-01(1).png') no-repeat -4px -9px; cursor: pointer; animation: rot 6s infinite linear var(--state); }
- @keyframes rot { to { transform: rotate(1turn); } }
- </style>
- <div id="papa">
- <div id="prog" data-cu="00:00" data-du="00:00" title="调节进度">
- <span id="btnplay" title="播放/暂停"></span>
- <span id="slider"></span>
- </div>
- </div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=29130919" autoplay loop></audio>
- <script>
- let toMin = (val) => { if (!val) return '00:00'; let min = parseInt(val / 60), sec = parseFloat(Math.floor(val) % 60); if(sec < 10) sec = '0' + sec; return min + ':' + sec; }
- let mState = () => prog.style.setProperty('--state', aud.paused ? 'paused' : 'running');
- aud.addEventListener('pause', mState, false);
- aud.addEventListener('play', mState, false);
- aud.addEventListener('timeupdate', () => { prog.style.setProperty('--prg', aud.currentTime / aud.duration * 100 + '%'); prog.dataset.cu = toMin(aud.currentTime); prog.dataset.du = toMin(aud.duration); });
- btnplay.onclick = (e) => { e.stopPropagation(); aud.paused ? aud.play() : aud.pause(); }
- prog.onclick = (e) => aud.currentTime = e.offsetX * aud.duration / prog.offsetWidth;
- </script>
复制代码
|
|