|
|

楼主 |
发表于 2022-10-20 20:00
|
显示全部楼层
源码- <style>
- #papa { margin: auto; width: 740px; height: 640px; background: gray; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; position: relative; }
- #mplayer { position: absolute; bottom: 0; }
- </style>
- <div id="papa">
- <svg id="mplayer" width="360" height="60" style="user-select: none;">
- <rect x="50" y="25" rx="6" ry="6" width="200" height="12" stroke="hsla(60,80%,92%,.75)" fill="hsla(60,100%,92%,.35)" id="track" />
- <rect x="50" y="25" rx="6" ry="6" width="0" height="12" stroke="transparnet" fill="hsla(60,80%,92%,.75)" id="prog" />
- <text x="260" y="31" font-size="14" dominant-baseline="middle" stroke="none" fill="gold" id="audtime">00:00 | 00:00</text>
- <text x="10" y="35" font-size="40" dominant-baseline="middle" stroke="yellow" fill="gold" id="btnplay" style="cursor: pointer;">☀
- <animateTransform attributeName="transform" dur="4s" type="rotate" from="0 26.86 30" to="360 26.86 30" repeatCount="indefinite" />
- </text>
- </svg>
- </div>
- <script>
- let mp = { len: track.getAttribute('width')*1, x: track.getAttribute('x')*1 }, aud = new Audio();
- aud.src = 'https://music.163.com/song/media/outer/url?id=1911004729.mp3';
- aud.autoplay = true;
- aud.loop = true;
- btnplay.onclick = () => aud.paused ? (aud.play(), mplayer.unpauseAnimations()) : (aud.pause(), mplayer.pauseAnimations());
- prog.onclick = track.onclick = (e) => aud.currentTime = aud.duration * (e.offsetX - mp.x) / mp.len;
- aud.addEventListener('pause', () => mState());
- aud.addEventListener('play', () => mState());
- aud.addEventListener('timeupdate', () => {
- prog.style.setProperty('width', aud.currentTime * 200 / aud.duration + 'px');
- audtime.textContent = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);
- });
- let mState = () => aud.paused ? mplayer.pauseAnimations() : mplayer.unpauseAnimations();
- 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;}
- if(aud.paused) mplayer.pauseAnimations();
- </script>
复制代码
|
|