|
|

楼主 |
发表于 2022-11-8 08:00
|
显示全部楼层
本帖最后由 马黑黑 于 2022-11-8 09:00 编辑
代码- <style>
- #papa {
- margin: calc(50% - 581px);
- width: 1024px;
- height: 640px;
- background: gray;
- display: grid;
- place-items: center;
- box-shadow: 3px 3px 20px #000;
- user-select: none;
- position: relative;
- z-index: 1;
- }
- #mplayer {
- position: absolute;
- bottom: 20px;
- grid-template-columns: auto auto auto;
- gap: 6px;
- display: grid;
- place-items: center;
- }
- #btnplay {
- margin-right: -4px;
- width: 30px;
- height: 30px;
- color: red;
- font: bold 30px/30px serif;
- text-align: center;
- cursor: pointer;
- animation: rot 4s infinite linear;
- animation-play-state: var(--state);
- --state: paused;
- }
- #tmsg {
- font: normal 16px sans-serif;
- color: #eee;
- }
- #prog {
- width: 200px;
- height: 20px;
- cursor: pointer;
- }
- #lrc {
- --state: running;
- --motion: cover1;
- --tt: 5s;
- 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));
- }
- #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, 20%, 50%, .45), hsla(240, 50%, 60%, .75));
- 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">
- <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=1977849891.mp3" loop autoplay></audio>
- <script>
- (function() {
- let mKey = 0,
- mSeek = false,
- mFlag = true;
- let lrcAr = [
- [1, "许篮心 - 月落的声音", 2],
- [2.04, "你看啊 皎白的月 那么闪亮", 6.0],
- [8.04, "你听啊 谁在唱动人的歌谣", 6.0],
- [14.04, "你看啊 温柔的光 照亮远方", 6.0],
- [20.05, "我愿把 一路沧桑原谅", 6.0],
- [51.02, "潇潇落雨", 1.0],
- [52.06, "悄悄爱你", 1.9],
- [54.01, "是花开的声音", 2.2],
- [57.01, "悄悄想你是月落的声音", 4.8],
- [63.08, "舍不得删掉通讯录里那个名字", 4.3],
- [69.07, "却再听不到独一无二的嗓音", 4.0],
- [75.08, "鸟飞去雾里再也没有归期", 4.0],
- [80.01, "剩下另一只孤零零站在风里", 5.3],
- [87.02, "潇潇落雨", 1.0],
- [88.06, "悄悄哭泣", 2.0],
- [90.01, "是花落的声音", 3.0],
- [93.01, "悄悄抱紧是雪化的声音", 5.0],
- [98.1, "你看啊 皎白的月 那么闪亮", 5.8],
- [104.04, "你听啊 谁在唱动人的歌谣", 6.0],
- [110.05, "你看啊 温柔的光 照亮远方", 6.0],
- [116.05, "我愿把 一路沧桑原谅", 6.1],
- [123.02, "潇潇落雨", 1.0],
- [124.06, "悄悄爱你", 2.0],
- [126.02, "是花开的声音", 2.2],
- [129.02, "悄悄想你是月落的声音", 4.8],
- [135.01, "潇潇落雨", 1.0],
- [136.05, "悄悄回忆", 2.0],
- [138.01, "悄悄离开你", 2.0],
- [141.01, "是云消散于天空的沉寂", 4.7],
- [146.06, "你看啊 蓝色星星 铺满路上", 6.0],
- [152.03, "你听啊 风铃转动 着遥望", 6.0],
- [158.04, "你在哪 回忆中错过的时光", 6.0],
- [164.05, "我们啊 故事遗落在海上", 6.0],
- [170.05, "nuneila a ba za ali za li li", 6.0],
- [176.04, "nunala a sa za a mi mu guagua", 6.0],
- [182.04, "nuneila em caz a a li ba li li", 6.0],
- [188.05, "adujia atipadenisasa", 6.9],
- ];
- 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>
复制代码
|
|