|
|

楼主 |
发表于 2022-9-2 06:57
|
显示全部楼层
代码
- <style>
- #papa { left: -214px; width: 1024px; height: 640px; background: gray url('/data/attachment/forum/202209/02/065401ejiwmso2m2oag1ci.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; display:grid; place-items: center; user-select: none; overflow: hidden; position: relative; z-index: 1; }
- #mplayer { position: absolute; bottom: 10px; right: 10px; width: fit-content; height: fit-content; display: flex; align-items: center; gap: 8px; z-index: 9; }
- #btnwrap { position: relative; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: #ccc linear-gradient(to top right, rgba(255,0,0,.75), rgba(0,255,0,.75)); cursor: pointer; }
- #btnwrap:hover { background: #000 linear-gradient(to top right, rgba(255,0,0,.75), rgba(0,255,0,.75)); }
- #btnplay { width: 20px; height: 20px; 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; }
- #prog { width: 300px; height: 2px; background: #ccc linear-gradient(to right,red,orange,green,tomato) no-repeat; background-size: 1px 2px; cursor: pointer; position: relative; }
- #prog::before { position: absolute; content: ''; top: -7px; width: inherit; height: 15px; }
- #prog:hover::before { background: rgba(0,200,200,.15); }
- #tmsg { font: normal 16px sans-serif; color: lightblue; }
- #lrc { position: absolute; left: 10px; bottom: 10px; font: bold 1.5em sans-serif; color: lightblue; text-shadow: 1px 1px 2px #000; text-align: center; }
- #lrc:hover, #tmsg:hover { color: snow; }
- #vid { position: absolute; width: 1024px; height: 695px; top: -55px; object-fit: cover; opacity: 0.25; }
- </style>
- <div id="papa">
- <video id="vid" src="https://img.tukuppt.com/video_show/2422006/00/03/03/5ba38e0f3bdba.mp4" muted="muted" autoplay="autoplay" loop="loop"></video>
- <div id="mplayer"><span id="btnwrap"><span id="btnplay"></span><span id="btnpause"></span></span><span id="prog"></span><span id="tmsg">00:00 | 00:00</span></div>
- <div id="lrc">lrc歌词</div>
- </div>
- <script>
- let lrcAr = [
- ['0.00','纯音乐 - 冰河'],
- ['160.00','感谢支持']
- ];
- let aud = new Audio();
- aud.src = 'https://music.163.com/song/media/outer/url?id=1295445124.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.backgroundSize = prog.offsetWidth * aud.currentTime / aud.duration + 'px 2px';
- tmsg.innerText = toMin(aud.duration) + ' | ' + toMin(aud.currentTime);
- for(j=0; j<lrcAr.length; j++) {
- if(aud.currentTime >= lrcAr[j][0]) lrc.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>
复制代码
|
|