|
|

楼主 |
发表于 2022-9-19 07:27
|
显示全部楼层
代码
- <style>
- #papa { left: -214px; width: 1024px; height: 640px; background: #ccc url('/data/attachment/forum/202209/19/072429vo4tzt453j6soj36.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; overflow: hidden; position: relative; z-index: 1; }
- #mplayer { position: absolute; left: 10px; bottom: 10px; }
- #btnwrap { display: block; fill: #ccc; cursor: pointer; }
- #btnwrap:hover { fill: orange; }
- #tmsg { fill: snow; stroke: gray; stroke-width: 1px; font: bold 1em sans-serif; }
- #lrc { position: absolute; bottom: 10px; right: 100px; font: bold 2em sans-serif; color: transparent; letter-spacing: 2px; background: linear-gradient(-90deg, purple, orange) 100% 100% / 200% 200%; background-clip: text; -webkit-background-clip: text; }
- #feather {position: absolute; left: 0; top: 0; width: 50px;offset-distance: 0;offset-path: path("M500 -60 Q300 80, 600 200 T900 640");animation: move 8s linear infinite;}
- @keyframes bgMove1 { from { background-position: 0 0; } to { background-position: -100% 0; } }
- @keyframes bgMove2 { from { background-position: 0 0; } to { background-position: -100% 0; } }
- @keyframes move { to { offset-distance: 100%;} }
- </style>
- <div id="papa">
- <img id="feather" src="/data/attachment/forum/202209/19/072054nefdifokfiaonowf.png" alt="" />
- <div id="lrc">花潮lrc在线</div>
- <svg id="mplayer" width="120" height="120">
- <g id="mama" transform="rotate(-90, 60, 60)" style="cursor: pointer;">
- <circle id="track" cx="60" cy="60" r="50" fill="none" stroke-width="10" stroke="rgba(255,255,255,0.65)" />
- <circle id="prog" cx="60" cy="60" r="50" fill="none" stroke-width="6" stroke="rgba(57,54,81,0.85)" />
- </g>
- <g id="btnwrap">
- <path id="btnplay" d="M 50 50,50 70,70, 60 z"></path>
- <path id="btnpause" d="M 52 50,52 70,57 70,57 50,52 50 z M 60 50,60 70,65 70,65 50,60 50 z"></path>
- <path d="M 57 50,60 50,60 70,57 70 z" fill="transparent" />
- </g>
- <path id="curPath" d="M 20 70 Q 60 0 100 70" fill="none" stroke="none"/>
- <path id="durPath" d="M 20 55 Q 60 110 100 55" fill="none" stroke="none"/>
- <g id="tmsg">
- <text x="34" y="0"><textPath id="curMsg" xlink:href="#curPath" dominant-baseline="text-after-edge">00:00</textPath></text>
- <text x="29" y="0"><textPath id="durMsg" xlink:href="#durPath" dominant-baseline="text-before-edge">00:00</textPath></text>
- </g>
- </svg>
- </div>
- <script>
- let lrcAr = [
- [0.00,'作词 : 田漢 作曲 : 贺绿汀',6],
- [6.25,'演唱 :周旋',5],
- [21.65,'天涯呀海角',7],
- [29.18,'觅呀觅知音',4.2],
- [36.09,'小妹妹唱歌郎奏琴',5],
- [42.02,'郎呀咱们俩是一条心',5],
- [52.84,'嗳呀嗳呀',2],
- [55.43,'郎呀咱们俩是一条心',5],
- [66.56,'家山呀北望泪呀泪沾襟',11.5],
- [80.28,'小妹妹想郎直到今',5],
- [86.03,'郎呀患难之交恩爱深',7],
- [96.87,'嗳呀嗳呀',2],
- [99.23,'郎呀患难之交恩爱深',5],
- [110.28,'人生呀谁不惜呀惜青春',12],
- [123.45,'小妹妹似线郎似针',5],
- [129.06,'郎呀穿在一起不离分',5],
- [139.62,'嗳呀嗳呀',2],
- [142.15,'郎呀穿在一起不离分',5]
- ];
- let mKey = 0, mSeek = false, mFlag = true;
- 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(),
- };
- prog.style.strokeDasharray = prog.style.strokeDashoffset =cc.len;
- aud.src = 'https://music.163.com/song/media/outer/url?id=1809278238.mp3';
- aud.autoplay = true;
- aud.loop = true;
- 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;
- };
- btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
- aud.addEventListener('pause', () => mState());
- aud.addEventListener('play', () => mState());
- aud.addEventListener('seeked', () => calcKey());
- aud.addEventListener('timeupdate', () => {
- prog.style.strokeDashoffset = cc.len - cc.len * aud.currentTime / aud.duration;
- curMsg.textContent = toMin(aud.currentTime);
- durMsg.textContent = toMin(aud.duration);
- for(j=0; j<lrcAr.length; j++) {
- if(aud.currentTime >= lrcAr[j][0]) {
- if(mKey === j) showLrc(lrcAr[j][2]);
- else continue;
- }
- }
- });
- let mState = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none', lrc.style.animationPlayState = 'paused') : (btnplay.style.display = 'none', btnpause.style.display = 'block', lrc.style.animationPlayState = 'running');
- let showLrc = (time) => {
- lrc.style.animation = (mFlag ? 'bgMove1 ' : 'bgMove2 ') + time + 's linear forwards';
- lrc.innerHTML = lrcAr[mKey][1];
- mKey += 1;
- mFlag = !mFlag;
- }
- let calcKey = () => {
- for(j = 0; j < lrcAr.length; j ++) {
- if(aud.currentTime <= lrcAr[j][0]) {
- mKey = j - 1;
- break;
- }
- }
- if(mKey <0) mKey = 0;
- if(mKey > lrcAr.length - 1) mKey = lrcAr.length - 1;
- let mtime = lrcAr[mKey][2] - (aud.currentTime - lrcAr[mKey][0]);
- showLrc(mtime);
- }
- 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>
复制代码
|
|