|
|

楼主 |
发表于 2022-9-7 09:13
|
显示全部楼层
源码
- <style>
- #papa { position: relative; left: 202px; display: block; margin: auto; box-shadow: 2px 2px 10px #000; user-select: none; z-index: 1; }
- #mama { cursor: pointer; }
- #tit { font: bold 3em sans-serif; text-shadow: 4px 4px 0 #000; stroke-width: 0.5px; stroke: snow; fill: none; dominant-baseline: text-before-edge; letter-spacing: 4px; }
- #tmsg { fill: transparent; stroke: gray; stroke-width: 1px; font: bold 1em sans-serif; }
- #btnplay, #btnpause { fill: #ccc; cursor: pointer; display: block; }
- #btnpause { display: none; }
- #btnplay:hover, #btnpause:hover { fill: orange; }
- </style>
- <svg id="papa" width="1000" height="553">
- <image xlink:href="/data/attachment/forum/202209/07/090849t9n9xgz2rnlaqgbl.jpg" x="0" y="0" width="100%" height="100%" />
- <g id="mama" transform="rotate(-90, 900, 453)">
- <circle id="track" cx="900" cy="453" r="50" fill="none" stroke-width="10" stroke="rgba(255,255,255,0.65)" />
- <circle id="prog" cx="900" cy="453" r="50" fill="none" stroke-width="6" stroke="rgba(57,54,81,0.85)" />
- </g>
- <polygon id="btnplay" points="890 443, 890 463, 910 453" />
- <g id="btnpause">
- <rect x="892" y="443" width="5" height="20" />
- <rect x="900" y="443" width="5" height="20" />
- </g>
- <path id="curPath" d="M 850 463 Q 900 400 950 463" fill="none" stroke="none"/>
- <path id="durPath" d="M 850 443 Q 900 500 950 443" fill="none" stroke="none"/>
- <g id="tmsg">
- <text x="40" y="0"><textPath id="curMsg" xlink:href="#curPath" dominant-baseline="text-after-edge">00:00</textPath></text>
- <text x="38" y="0"><textPath id="durMsg" xlink:href="#durPath" dominant-baseline="text-before-edge">00:00</textPath></text>
- </g>
- <text id="tit" x="20" y="20">梦驼铃</text>
- </svg>
- <script>
- let aud = new Audio();
- let cc = {
- x: 1*track.getAttribute('cx'),
- y: 1*track.getAttribute('cy'),
- r: 1*track.getAttribute('r'),
- sw: 1*track.getAttribute('stroke-width'),
- len: track.getTotalLength(),
- };
- aud.src = 'https://music.163.com/song/media/outer/url?id=1911002130.mp3';
- aud.autoplay = true;
- aud.loop = true;
- prog.style.strokeDasharray = prog.style.strokeDashoffset =cc.len;
- aud.addEventListener('pause', () => btnstate());
- aud.addEventListener('play',() => btnstate());
- aud.addEventListener('timeupdate', () => {
- prog.style.strokeDashoffset = cc.len - cc.len * aud.currentTime / aud.duration;
- curMsg.textContent = toMin(aud.currentTime);
- durMsg.textContent = toMin(aud.duration);
- });
- btnplay.onclick = btnpause.onclick = () => aud.paused ? aud.play() : aud.pause();
- mama.onclick = (e) => {
- let deg = Math.atan2(e.offsetY - cc.y, e.offsetX - cc.x) * 180 / Math.PI;
- deg += (e.offsetX < cc.x && e.offsetY < cc.y) ? 450 : 90;
- aud.currentTime = aud.duration * deg / 360;
- };
- 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>
复制代码
|
评分
-
| 参与人数 1 | 威望 +30 |
金钱 +60 |
经验 +30 |
收起
理由
|
加林森
| + 30 |
+ 60 |
+ 30 |
很给力! |
查看全部评分
|