|
|

楼主 |
发表于 2022-9-5 07:01
|
显示全部楼层
代码(全)
- <style>
- #papa { left: -214px; width: 1024px; height: 640px; background: #666 url('https://638183.freep.cn/638183/t22/hl/h59.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; user-select: none; position: relative; z-index: 1;}
- #mplayer { position: absolute; padding: 0; margin: 20px; width: 120px; height: 120px; border-radius: 50%; overflow: hidden; }
- #prog, #track { stroke: url(#gradient); }
- #lrc { position: absolute; display: block; left: 20px; bottom: 0; }
- #lrctxt { dominant-baseline: middle; fill: url(#gradient); font: bold 2em sans-serif; text-shadow: 0 4px 0 #000; letter-spacing: 2px; }
- </style>
- <div id="papa">
- <div id="mplayer">
- <svg width="100%" height="100%" shape-rendering="geometricPrecision">
- <g transform="rotate(-90, 60, 60)">
- <circle id="track" cx="60" cy="60" r="55" fill="none" stroke="rgba(255,255,255,.5)" stroke-width="10" stroke-dasharray="2" stroke-opacity="0.45" />
- <circle id="prog" cx="60" cy="60" r="55" fill="none" stroke="red" stroke-width="10" />
- </g>
- <text fill="orange">
- <tspan id="cur" x="40" y="55">00:00</tspan>
- <tspan id="dur" x="40" y="75">00:00</tspan>
- </text>
- </svg>
- </div>
- <svg id="lrc" width="400" height="50">
- <defs>
- <linearGradient id="gradient" x1="0" y1="0" x2="0" y2="1">
- <stop offset="0%" stop-color="green"/>
- <stop offset="50%" stop-color="orange"/>
- <stop offset="100%" stop-color="red"/>
- </linearGradient>
- </defs>
- <text id="lrctxt" x="0" y="25">黄龄 - HIGH歌</text>
- </svg>
- </div>
- <script>
- let lrcAr = [
- ['0.00','黄龄 - High歌'],
- ['6.00','作词/作曲:常石磊'],
- ['9.00','歌词编辑:孟德良'],
- ['17.04','Mountain top'],
- ['19.05','就跟着一起来'],
- ['21.09','没有什么 阻挡着未来'],
- ['26.04','Deeping night'],
- ['28.05','就你和我的爱'],
- ['30.07','没有什么 阻挡着未来'],
- ['35.03','Mountain top'],
- ['37.03','就跟着一起来'],
- ['39.06','没有什么 阻挡着未来'],
- ['44.01','Deeping night'],
- ['46.01','就你和我的爱'],
- ['48.05','没有什么 阻挡着未来'],
- ['53.00','Mountain top'],
- ['54.09','就跟着一起来'],
- ['57.04','没有什么 阻挡着未来'],
- ['61.10','Deeping night'],
- ['63.09','就你和我的爱'],
- ['66.03','没有什么 阻挡着未来'],
- ['70.08','Yi Yi Yi 你不在 我不在'],
- ['75.03','Yi Yi Yi 谁还会在'],
- ['79.07','Yi Yi Yi 你不在 我不在'],
- ['84.02','Yi Yi Yi 谁还会在'],
- ['124.02','Mountain top'],
- ['126.00','就跟着一起来'],
- ['128.05','没有什么 阻挡着未来'],
- ['132.10','Deeping night'],
- ['135.00','就你和我的爱'],
- ['137.04','没有什么 阻挡着未来'],
- ['141.09','Yi Yi Yi 你不在 我不在'],
- ['146.04','Yi Yi Yi 谁还会在'],
- ['150.07','Yi Yi Yi 你不在 我不在'],
- ['155.03','Yi Yi Yi 谁还会在'],
- ['204.03','Mountain top'],
- ['208.04','就一起来'],
- ['213.00','Mountain top'],
- ['217.03','就一起来'],
- ['221.08','Mountain top'],
- ['225.10','就一起来'],
- ['230.07','Mountain top'],
- ['235.01','就一起来']
- ];
- let aud = new Audio();
- aud.src = 'https://music.163.com/song/media/outer/url?id=238634.mp3';
- aud.autoplay = true;
- aud.loop = true;
- //设置圆环进度偏移
- let girth = prog.getTotalLength();
- prog.style.strokeDasharray = prog.style.strokeDashoffset = girth+ 'px';
- //圆环鼠标经过
- mplayer.onmousemove = (e) => {
- if (isHover(e.offsetX, e.offsetY)) mplayer.style.cursor = 'pointer';
- }
- //圆环点击
- mplayer.onclick = (e) => {
- if (isHover(e.offsetX, e.offsetY)) { //轨道
- let deg = Math.atan2(e.offsetY - 60, e.offsetX - 60) * 180 / Math.PI;
- deg += (e.offsetX < 60 && e.offsetY < 60) ? 450 : 90;
- aud.currentTime = aud.duration * deg / 360;
- } else { //内区域
- aud.paused ? aud.play() : aud.pause();
- }
- }
- //监听播放进度
- aud.addEventListener('timeupdate', () => {
- prog.style.strokeDashoffset = girth - girth * aud.currentTime / aud.duration + 'px';
- cur.textContent = toMin(aud.currentTime);
- dur.textContent = toMin(aud.duration);
- for(j=0; j<lrcAr.length; j++) {
- if(aud.currentTime >= lrcAr[j][0]) lrctxt.textContent = lrcAr[j][1];
- }
- });
- //圆检测鼠标经过
- let isHover = (x,y) => Math.pow(x - 60, 2) + Math.pow(y - 60, 2) >= Math.pow(45, 2);
- //时间信息格式化
- 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>
复制代码
|
|