|
|

楼主 |
发表于 2022-11-9 07:22
|
显示全部楼层
参考代码
- <style>
- #papa {
- margin: 100px 0 0 calc(50% - 621px);
- width: 1080px;
- height: 721px;
- background: gray url('https://638183.freep.cn/638183/t22/webp/mgtm.webp') no-repeat center/cover;
- display: grid;
- place-items: center;
- box-shadow: 3px 3px 20px #000;
- user-select: none;
- overflow: hidden;
- perspective: 1000px;
- position: relative;
- z-index: 1;
- }
- #mplayer {
- position: absolute;
- bottom: 20px;
- grid-template-columns: auto auto auto;
- gap: 6px;
- display: grid;
- place-items: center;
- font: normal 16px sans-serif;
- color: snow;
- z-index: 999;
- }
- #btnplay {
- margin-right: -4px;
- width: 30px;
- height: 30px;
- font: bold 30px/30px serif;
- text-align: center;
- cursor: pointer;
- animation: rot 4s infinite linear;
- animation-play-state: var(--state);
- --state: paused;
- }
- #prog {
- width: 200px;
- height: 20px;
- cursor: pointer;
- }
- #lrc {
- --state: running;
- --motion: cover2;
- --tt: 1s;
- position: absolute;
- top: 20px;
- font: bold 2.4em sans-serif;
- color: hsl(240, 50%, 90%);
- -webkit-background-clip: text;
- filter: drop-shadow(1px 1px 2px hsla(30, 10%, 10%, .95));
- z-index: 1000;
- }
- #lrc::before {
- position: absolute;
- content: attr(data-lrc);
- width: 20%;
- height: 100%;
- color: transparent;
- overflow: hidden;
- white-space: nowrap;
- background: linear-gradient(180deg, hsla(240, 60%, 50%, .45), hsla(240, 100%, 60%, .75));
- filter: inherit;
- -webkit-background-clip: text;
- animation: var(--motion) var(--tt) linear forwards;
- animation-play-state: var(--state);
- }
- .star {
- --rr: 300px;
- position: absolute;
- width: 4px;
- height: 4px;
- border-radius: 50% 50% 25% 50%;
- transform-origin: 50% 50%;
- transform-style: preserve-3d;
- }
- @keyframes cover1 { from { width: 0; } to { width: 100%; } }
- @keyframes cover2 { from { width: 0; } to { width: 100%; } }
- @keyframes rot { to { transform: rotate(1turn); } }
- @keyframes fly { to { transform: rotate(0) translate(0); } }
- </style>
- <div id="papa">
- <div id="lrc" data-lrc="花潮论坛lrc在线">花潮论坛lrc在线</div>
- <div id="mplayer">
- <span id="btnplay">◑</span>
- <meter id="prog" low="30" high="90" max="100" optimum="100" value="1"></meter>
- <span id="tmsg">00:00 | 00:00</span>
- </div>
- </div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=283101.mp3" loop autoplay></audio>
- <script>
- (function() {
- let mKey = 0, mSeek = false, mFlag = true;
- let lrcAr = [[0.05,"词:三毛 曲:翁孝良 演唱:潘越云 齐豫",1.0],[12,"每个人心里一亩",2.1],[14.06,"一亩田",3.0],[18.58,"每个人心里一个",3.0],[21.07,"一个梦",4.0],[25.49,"一颗芽",1.9],[27,"一颗种子",1.1],[28.37,"是我心里的",2.0],[30.06,"一亩田",3.9],[37.02,"每个人心里一亩",2.1],[39.38,"一亩田",4.9],[44.01,"每个人心里一个",2.1],[46.48,"一个梦",4.0],[51.02,"一颗芽",1.0],[52.03,"一颗种子",1.0],[53.39,"是我心里的",2.0],[55.07,"一亩田",6.0],[62.02,"用它来种什么",2.0],[64.57,"用它来种什么",3.0],[67.59,"种桃种李",2.0],[69.06,"种春风",4.0],[73.06,"用它来种什么",3.0],[76.03,"用它来种什么",2.0],[79.01,"种桃种李",1.1],[80.19,"种春风",4.0],[84.38,"开尽梨花 ",4.9],[89.02,"春又来 ",3.0],[96.02,"Ah ...",8.0],[104.05,"Ah ...",13.0],[118.02,"用它来种什么",2.0],[120.57,"用它来种什么",3.0],[123.58,"种桃种李",2.0],[125.25,"种春风",4.0],[129.44,"用它来种什么",3.0],[132.02,"用它来种什么",2.0],[135,"种桃种李",1.1],[136.08,"种春风",4.0],[140.27,"开尽梨花",5.0],[145.03,"春又来",6.0],[152.01,"那是我",1.0],[153.01,"心里一亩",1.1],[154.08,"一亩田",3.9],[158.48,"那是我心里一个",3.0],[161.06,"不醒的梦 啊 ……",10.0],];
- (function() {
- Array.from({length: 100}).forEach((item,key) => {
- item = document.createElement('span');
- item.className = 'star';
- let ww = Math.ceil(Math.random() * 20) | 10;
- item.style.cssText += `
- width: ${ww}px;
- height: ${ww}px;
- left: ${Math.random()*200 + 500}px;
- top: ${Math.random()*100 + 240}px;
- background: hsla(${360*Math.random()},100%,50%,.75);
- transform: rotate(${Math.random() * 720}deg) translate3d(${Math.random() * 500}px,${Math.random() * 300}px,${Math.random() * 1000}px);
- animation: fly 80s infinite ${-10 - Math.random() * 20}s linear;
- `;
- papa.appendChild(item);
- });
- })();
- btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
- prog.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth;
- aud.addEventListener('pause', () => mState());
- aud.addEventListener('play', () => mState());
- aud.addEventListener('seeked', () => calcKey());
- aud.addEventListener('timeupdate', () => {
- prog.value = aud.currentTime / aud.duration * 100;
- tmsg.innerText = `${toMin(aud.currentTime)} | ${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.setProperty('--state', 'paused'), lrc.style.setProperty('--state', 'paused')) : (btnplay.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 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>
复制代码
|
|