|
|

楼主 |
发表于 2022-9-11 07:44
|
显示全部楼层
代码:
- <style>
- #papa { left: -214px; width: 1024px; height: 640px; background: gray url('https://638183.freep.cn/638183/t22/hl/ewav.png') 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; 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: linear-gradient(to top right, lightblue, blue); cursor: pointer; }
- #btnwrap:hover { background: #000 linear-gradient(to top right, snow, teal); }
- #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,blue,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(200,200,200,.15); }
- #tmsg { font: normal 16px sans-serif; color: snow; }
- #lrc { position: absolute; left: 20px; top: 20px; font: bold 1.5em sans-serif; color: skyblue; text-shadow: 2px 2px 2px #222; opacity: 1; animation: opa 1.5s infinite alternate; }
- #wave { position: absolute; display: block; top: 0; }
- @keyframes opa { to { opacity: .3;} }
- </style>
- <div id="papa">
- <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"></div>
- <svg id="wave" width="600" height="600"> <!-- 模拟电波 -->
- <circle cx="300" cy="300" r="0" fill="none" stroke="lightgreen" stroke-width="4">
- <animate attributeName="r" begin="0s" from="0" to="290" dur="2s" repeatCount="indefinite"></animate>
- <animate attributeName="stroke-opacity" begin="0s" from="0.5" to="0" dur="2s" repeatCount="indefinite"></animate>
- </circle>
- <circle cx="300" cy="300" r="0" fill="none" stroke="skyblue" stroke-width="3">
- <animate attributeName="r" begin="0.5s" from="0" to="290" dur="2s" repeatCount="indefinite"></animate>
- <animate attributeName="stroke-opacity" begin="0.5s" from="0.5" to="0" dur="2s" repeatCount="indefinite"></animate>
- </circle>
- <circle cx="300" cy="300" r="0" fill="none" stroke="lightblue" stroke-width="2">
- <animate attributeName="r" begin="1s" from="0" to="290" dur="2s" repeatCount="indefinite"></animate>
- <animate attributeName="stroke-opacity" begin="1s" from="0.5" to="0" dur="2s" repeatCount="indefinite"></animate>
- </circle>
- <circle cx="300" cy="300" r="0" fill="none" stroke="red" stroke-width="1">
- <animate attributeName="r" begin="1.5s" from="0" to="290" dur="2s" repeatCount="indefinite"></animate>
- <animate attributeName="stroke-opacity" begin="1.5s" from="0.5" to="0" dur="2s" repeatCount="indefinite"></animate>
- </circle>
- </svg>
- </div>
- <script>
- let lrcAr = [
- ['0.00','永不消逝的电波'],
- ['240.00','感谢支持']
- ];
- let aud = new Audio();
- aud.src = 'https://music.163.com/song/media/outer/url?id=1860681142.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>
复制代码
|
|