|
|

楼主 |
发表于 2022-11-3 07:21
|
显示全部楼层
代码
- <style>
- #papa { margin: auto; width: 1024px; height: 683px; background: silver url('https://638183.freep.cn/638183/t22/webp/qyrh.webp') no-repeat center/cover; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; user-select: none; position: relative; z-index: 1; }
- #mplayer { position: absolute; width: 400px; height: 110px; left: 20px; bottom: 10px; font: normal 14px sans-serif; z-index: 9; }
- #mplayer::before, #mplayer::after { position: absolute; width: 100%; height: 50%; color: tan; margin: 70px 0; }
- #mplayer::before { content: attr(data-cur); }
- #mplayer::after { content: attr(data-dur); text-align: right; }
- .btnplay { position: absolute; width: 40px; height: 20px; left: 50%; top: 48px; background: linear-gradient(to left,hsla(120,50%,70%,.6),hsla(60,80%,50%,.7)); border-radius: 0 100%; transform-origin: 0 0; animation: rot linear 4s infinite; animation-play-state: paused; }
- .btnplay::before, .btnplay::after { position: absolute; width: 100%; height: 100%; content: ''; background: inherit; border-radius: inherit; transform-origin: 0 0; transform: rotate(120deg); }
- .btnplay::after { transform: rotate(240deg); }
- #prog { --posX: 0px; position: absolute; bottom: 10px; width: 100%; height: 1px; background: tan; cursor: pointer; }
- #prog::before, #prog::after { position: absolute; content: ''; left: 0; }
- #prog::before { width: var(--posX); height: 1px; background: green; }
- #prog::after { left: var(--posX); top: calc(50% - 5px); width: 3px; height: 10px; background: darkgreen; }
- #lrc { --motion: cover1; --tt: 1s; --state: paused; position: absolute; right: 20px; bottom: 15px; font: bold 2.4em sans-serif; color: hsl(240,100%,90%); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px hsla(0,100%,0%,.85)); }
- #lrc::before { position: absolute; content: attr(data-lrc); width: 20%; height: 100%; color: transparent; overflow: hidden; white-space: nowrap; background: linear-gradient(180deg,hsla(120,30%,50%,.75),hsla(60,100%,50%,.65)); filter: inherit; -webkit-background-clip: text; animation: var(--motion) var(--tt) linear forwards; animation-play-state: var(--state); }
- @keyframes cover1 { from { width: 0; } to { width: 100%; } }
- @keyframes cover2 { from { width: 0; } to { width: 100%; } }
- @keyframes rot { to { transform: rotate(1turn); } }
- </style>
- <div id="papa">
- <div id="lrc" data-lrc="花潮论坛lrc在线">花潮论坛lrc在线</div>
- <div id="mplayer" data-cur="00:00" data-dur="00:00">
- <span id="prog"></span>
- <span class="btnplay"></span>
- </div>
- </div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=26222194.mp3" autoplay loop>audio api</audio>
- <script>
- (function() {
- let mKey = 0, mFlag = true, btnplay = document.querySelector('.btnplay');
- let lrcAr = [[1,"陈瑞",12.6],[32.57,"春天的美是花以成海",5.4],[38.79,"花海中的她是待放的蕾",5.8],[45.19,"爱上了她我无怨无悔",5.8],[51.42,"不知不觉走过四季轮回",5.2],[59.1,"秋天的叶虽已很疲惫",5.2],[64.73,"为了花更美你总说不累",5.8],[71.01,"没人留意你的美",6.0],[77.27,"我要为你送上鲜艳的玫瑰",5.3],[83.61,"秋叶如花我不能不在意",5.6],[90.8,"眼前浮华会成为累赘",5.0],[96.41,"唯有秋叶默默的为了我",5.6],[102.86,"孕育心中爱的花蕾",5.6],[109.43,"秋叶如花我已爱上你",5.6],[115.81,"梦中记忆已不再娇媚",5.6],[122.27,"那怕寒风冷也要陪着你",5.6],[128.78,"寻找那春天的芳菲 ",5.6],[162.6,"秋天的叶虽已很疲惫",5.1],[168.49,"为了花更美你总说不累",5.8],[174.82,"没人留意你的美",5.8],[181.7,"我要为你送上鲜艳的玫瑰",4.3],[187.26,"秋叶如花我不能不在意",5.6],[193.63,"眼前浮华会成为累赘",5.4],[200.18,"唯有秋叶默默的为了我",5.4],[206.5,"孕育心中爱的花蕾",5.6],[213.02,"秋叶如花我已爱上你",5.4],[219.5,"梦中记忆已不再娇媚",5.5],[226.06,"那怕寒风冷也要陪着你",5.3],[232.53,"寻找那春天的芳菲 ",5.2],[239.55,"寻找那春天的芳菲 ",7.7],];
- mplayer.onmousemove = (e) => {mplayer.style.cursor = e.offsetY > 90 ? 'pointer' : e.offsetY < 80 ? 'pointer' : 'default'; }
- mplayer.onclick = (e) => {if(e.offsetY > 90) {aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth;} else if(e.offsetY < 80) {aud.paused ? aud.play() : aud.pause();}}
- aud.addEventListener('pause', () => mState());
- aud.addEventListener('play', () => mState());
- aud.addEventListener('seeked', () => calcKey());
- aud.addEventListener('timeupdate', () => {prog.style.setProperty('--posX', prog.offsetWidth * aud.currentTime / aud.duration + 'px');mplayer.dataset.cur = toMin(aud.currentTime);mplayer.dataset.dur = 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.animationPlayState = 'paused', lrc.style.setProperty('--state', 'paused')) : (btnplay.style.animationPlayState = 'running', lrc.style.setProperty('--state', 'running'));
- let showLrc = (time) => {let name = mFlag ? 'cover1' : 'cover2';lrc.innerHTML = lrc.dataset.lrc = lrcAr[mKey][1];lrc.style.setProperty('--motion', name);lrc.style.setProperty('--tt', time + 's');lrc.style.setProperty('--state', 'running');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 time = lrcAr[mKey][2] - (aud.currentTime - lrcAr[mKey][0]);showLrc(time);};
- 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; };
- papa.oncontextmenu = () => false;
- (function() {for(j=0; j<50; j++) {let leaf = document.createElement('span');leaf.className = 'btnplay';leaf.style.cssText = `left: 80%;top: 45%;transform: rotate(${Math.random() * 360}deg) translate(${Math.random() * 150}px);`;papa.appendChild(leaf);}})();
- })();
- </script>
复制代码
|
|