|
|

楼主 |
发表于 2023-7-18 07:29
|
显示全部楼层
代码分享
- <style>
- #mydiv { margin: -80px 0 0 calc(50% - 681px); width: 1200px; height: 675px; background: #cc8c70 url('https://638183.freep.cn/638183/t23/2/wjkx.jpg') no-repeat center/cover; box-shadow: 0 0 8px 0 #000; opacity: .95; overflow: hidden; z-index: 1; position: relative; --state: paused; }
- #mydiv::before, #mydiv::after { position: absolute; content: '\1F982'; font-size: 60px; bottom: 15px; left: 40%; }
- #mydiv::after { content: '\1FAB2'; transform: translateY(15px) rotate(-10deg); font-size: 40px; }
- #lrc { position: absolute; top: 10px; left: 50%; transform: translate(-50%); font: bold 2.4em sans-serif; color: rgb(240,240,240); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px rgba(0,0,0,.95)); --motion: cover2; --tt: 5s; }
- #lrc::before { position: absolute; content: attr(data-lrc); width: 20%; height: 100%; color: transparent; overflow: hidden; white-space: nowrap; background: linear-gradient(180deg,rgba(112,145,180,.45),rgba(86,145,250,.75)); filter: inherit; -webkit-background-clip: text; animation: var(--motion) var(--tt) linear forwards var(--state); }
- pinpu-wrapper { position: absolute; bottom: 80px; left: 285px; cursor: pointer; }
- pin-pu { position: absolute; bottom: 0; animation: pinpuMotion var(--du) var(--delay) infinite alternate linear var(--state); --psw: 6px; }
- pin-pu::before { content: ''; position: absolute; left: calc(50% - var(--psw) / 2); width: var(--psw); height: var(--psw); border-radius: 50%; background: snow; }
- .mybox { position: absolute; top: -100px; left: 80%; font-size: 50px; animation: down 8s var(--delay) infinite linear var(--state); --delay: 0s; --deg: 5deg; }
- .mybox:nth-of-type(2) { --delay: -2s; --deg: -5deg; }
- .mybox:nth-of-type(3) { --delay: -4s; --deg: -15deg; }
- .mybox:nth-of-type(4) { --delay: -6s; --deg: -15deg; }
- @keyframes pinpuMotion { from { height: 0px; } to { height: var(--height); } }
- @keyframes down { to { transform: rotate(var(--deg)) translateY(800px) rotate(360deg); } }
- @keyframes cover1 { from { width: 0; } to { width: 100%; } }
- @keyframes cover2 { from { width: 0; } to { width: 100%; } }
- </style>
- <div id="mydiv">
- <span class="mybox">🪶</span>
- <span class="mybox">🪶</span>
- <span class="mybox">🪶</span>
- <span class="mybox">🪶</span>
- <pinpu-wrapper></pinpu-wrapper>
- <div id="lrc" data-lrc="花潮lrc在线">花潮lrc在线</div>
- </div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=346591" autoplay loop></audio>
- <script>
- +function() {
- let pinpuNum = 80, pinpuWidth = 4, pinpuHeight = 200, mKey = 0, mFlag = true, slip = 0.2; let ppwrap = document.querySelector('pinpu-wrapper');
- let lrcAr = [ [2," Beyond - 无尽空虚",22.5], [24.47,"为何在这里",3.0], [27.46,"疲倦像半醉",3.0], [30.49,"曾在这空间",2.6], [33.13,"跟你相拥抱",4.0], [37.72,"只有唏嘘的追忆",3.0], [40.67,"无言落寞地落泪",3.0], [43.66,"谁在这晚里放纵与她温馨",5.0], [48.65,"无尽空虚",4.1], [52.73,"似把刀锋静静穿过心窝 Wo",8.0], [60.71,"期待的爱",4.9], [65.58,"怎么一生总不可碰到 Wo",8.6], [86.42,"仍然在这里",3.0], [89.45,"无力像半醉",3.0], [92.43,"谁令我的心",2.6], [95.06,"此际多冰冷",4.6], [99.69,"只有唏嘘的追忆",2.9], [102.61,"无言落寞地落泪",3.0], [105.6,"谁在这晚里放纵与她温馨",5.0], [110.61,"无尽空虚",4.1], [114.68,"似把刀锋静静穿过心窝 Wo",8.0], [122.66,"期待的爱",4.9], [127.55,"怎么一生总不可碰到 Wo",8.0], [171.02,"无尽空虚",4.1], [175.08,"似把刀锋静静穿过心窝 Wo",8.0], [183.13,"期待的爱",4.1], [188.51,"怎么一生总不可碰到",7.2], [195.21,"无尽空虚",4.1], [199.32,"似把刀锋静静穿过心窝 Wo",9.0], [207.32,"期待的爱",4.1], [212.21,"怎么一生总不可碰到 Wo",9.0], [233.03,"La... La...",3.0], [236.03,"La... La...",3.0], [239.05,"La... La...",3.0], [242.06,"Da La Da La Da",3.0], [245.1,"La... La...",3.0], [248.09,"La... La...",3.0], [251.14,"La... La...",3.0], [254.16,"Da La Da La Da",3.0], [257.18,"La... La...",3.0], [260.16,"La... La...",3.0], [263.2,"La... La...",3.0], [266.22,"Da La Da La Da",5] ];
- let mState = () => aud.paused ? (mydiv.style.setProperty('--state','paused'), lrc.style.setProperty('--state','paused')) : (mydiv.style.setProperty('--state','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 msort = (ar) => {let newAr = [];ar.forEach((v,k) => k % 2 === 0 ? newAr.unshift(v) : newAr.push(v));return newAr;}
- +function() {let ar = Array.from(Array(pinpuNum), (v,k) => pinpuNum - k -1);Array.from({length: pinpuNum}).forEach((item,key) => {item = document.createElement('pin-pu');item.style.cssText += `width: ${pinpuWidth}px;left: ${(pinpuWidth + 2) * key}px;background: #${Math.random().toString(16).substr(-6)};--height: ${15 + (pinpuHeight - 15) / pinpuNum * msort(ar)[key]}px;--du: ${Math.random() * .3 + .3}s;--delay: -${Math.random()}s;--psw: ${pinpuWidth + 2}px`;ppwrap.appendChild(item);});ppwrap.style.height = `${pinpuHeight}px`;ppwrap.style.width = `${(pinpuWidth + 2) * pinpuNum}px`;}();
- aud.addEventListener('play', mState, false);
- aud.addEventListener('pause', mState, false);
- aud.addEventListener('seeked', calcKey, false);
- aud.addEventListener('timeupdate', () => {
- for (j = 0; j < lrcAr.length; j++) {if (aud.currentTime >= lrcAr[j][0] + slip) {cKey = j;if (mKey === j) showLrc(lrcAr[j][2]);else continue;}}});
- ppwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
- }();
- </script>
复制代码
|
|