|
|

楼主 |
发表于 2023-3-21 08:20
|
显示全部楼层
帖子代码
- <style>
- #papa { margin: -80px 0 0 calc(50% - 593px); width: 1024px; height: 640px; background: gray url('https://638183.freep.cn/638183/t23/webp/qi1.webp') center/cover no-repeat; box-shadow: 3px 3px 20px #000; position: relative; z-index: 1; }
- #mplayer { left: 50%; bottom: 20px; transform: translate(-50%); width: fit-content; height: fit-content; color: #333; position: absolute; --state: paused; --ww: 0px; }
- #mplayer::before, #mplayer::after { position: absolute; content: attr(data-cu); bottom: 16px; }
- #mplayer::before { left: 10px; }
- #mplayer::after { content: attr(data-du); right: 10px; }
- #btn { margin: auto; width: 50px; height: 72px; background: url('https://638183.freep.cn/638183/t23/btn/hvuz.webp'); background-position: 0 0; filter: drop-shadow(160px -136px 0 green); animation: hi 1s steps(10,jump-none) infinite var(--state); cursor: pointer; position: relative; }
- #btn::before { position: absolute; content: ''; width: inherit; height: inherit; cursor: inherit; left: 160px; top: -136px; }
- #prog { width: 300px; height: 6px; border: 1px solid #666; border-radius: 6px; display: grid; place-items: center start; position: relative; }
- #prog::before, #prog::after { position: absolute; content: ''; height: 6px; }
- #prog::before { background: red; border-radius: 10px; width: calc(var(--ww) + 16px); }
- #prog::after { left: var(--ww); width: 16px; height: 16px; background: red; border-radius: 50%; }
- @keyframes hi { to { background-position: 100% 0; } }
- </style>
- <div id="papa">
- <div id="mplayer" data-du="00:00" data-cu="00:00">
- <div id="btn"></div>
- <div id="prog"></div>
- </div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1860430971" autoplay loop></audio>
- </div>
- <script>
- (function(){
- 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;};
- btn.addEventListener('click', () => aud.paused ? aud.play() : aud.pause());
- aud.addEventListener('play', () => mplayer.style.setProperty('--state','running'));
- aud.addEventListener('pause', () => mplayer.style.setProperty('--state','paused'));
- aud.addEventListener('canplay', () => prog.style.setProperty('--time', aud.duration + 's'));
- aud.addEventListener('timeupdate', () => {mplayer.style.setProperty('--ww', mplayer.offsetWidth * aud.currentTime / aud.duration + 'px');mplayer.dataset.du = toMin(aud.duration);mplayer.dataset.cu = toMin(aud.currentTime);});
- prog.addEventListener('click', (e) => aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth);
- })();
- </script>
复制代码
|
|