注册时间2021-11-10
在线时间 小时
- 最后登录
- 1970-1-1
|
- <table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_504411">
- <style>
- #gc{margin: 120px -25%;position: relative;z-index: 1;width: 750px;}
- .lyrics{margin: 0;
- top: 0px;
- left: 50%;
- transform: translate(-50%, -50%);
- height: 100px; /* 调整高度,只容纳当前歌词 */
- text-align: center;
- position: absolute;z-index: 50;
- }
- .lyric-line{
- width: 100%;
- position: relative;
- height: 60px;
- overflow: visible;
- font: 300 50px '华文隶书', sans-serif;
- line-height: 60px;
- text-align: left;
- white-space: nowrap; /* 禁止换行 */
- filter: drop-shadow(#fff 1px 0 0) drop-shadow(#fff 0 1px 0) drop-shadow(#fff -1px 0 0) drop-shadow(#fff 0 -1px 0);
- }
- .lyric-mask {
- position: absolute;
- top: 0;
- left: 0;
- width: 0;
- overflow: hidden;
- color: #8B4513;
- height: 100%;
- white-space: nowrap;
- }
- .lyric-original {
- color: #ag0000;
- white-space: nowrap;
- }
- </style>
- <style>
- @keyframes an-pupils {
- from {transform: rotate(0deg);
- left: 60px;
- }
- to {transform: rotate(360deg);
- left: 0px;
- }
- }
- @keyframes an-ears {
- from {
- top:0;
- }
- to {
- top:25px;
- }
- }
- #cat {position: relative;
- width: 480px;z-index: 20;
- margin:20px auto;
- }
- #head {
- width: 400px;
- height: 370px;
- background-color: #171717;
- border-radius: 50%;
- margin: auto;
- }
- #ears {
- height: 65px;
- position: relative;
- left: 35px;
- animation-name: an-ears;
- animation-duration: 1s;
- animation-iteration-count: infinite;
- animation-direction: alternate-reverse;
- }
- .ear{
- width: 0;
- height: 0;
- border-left: 90px solid transparent;
- border-right: 90px solid transparent;
- border-bottom: 160px solid #171717;
- font-size: 0;
- line-height: 0;
- float: left;
- margin-right: 60px;
- transform: rotate(35deg);
- }
- .ear:first-child {
- transform: rotate(-35deg);
- }
- #eyes {
- clear: both;
- width: 350px;
- position: relative;
- top: 25px;
- left: 53px;
- }
- .eye {
- width: 120px;
- height: 120px;
- background-color: #FFFFFF;
- border-radius: 50%;
- float: left;
- }
- .eye:first-child {
- margin-right: 50px;
- }
- .pupil {
- position: relative;
- top:40px;
- background-color: #171717;
- border-radius: 50%;
- width: 80px;
- height: 80px;
- animation-name: an-pupils;
- animation-duration: 1.5s;
- animation-iteration-count: infinite;
- animation-direction: alternate-reverse;
- }
- .pupil_ref {
- background-color: #FFFFFF;
- border-radius: 45%;
- width: 30px;
- height: 30px;
- position: relative;
- top: 40px;
- left: 10px;
- }
- #nose {
- width: 45px;
- height: 30px;
- border-radius: 50%;
- background-color: #FFFFFF;
- position: relative;
- top: 160px;
- left: 170px;
- }
- #baffisx {
- position: relative;
- left: -100px;
- top: 100px; transform-origin: 70% 0%;
- animation: hue-rotate 1s linear infinite ;
- }
- @keyframes hue-rotate {
- from {transform: rotate(-15deg);margin: 0px 0px;
- }
- to {margin: 0px 0px;transform: rotate(15deg);
- }
- }
- #baffidx {
- position: relative;
- left: 223px;
- top: 140px;
- transform-origin: 0% 0%;
- animation: hue 1s linear infinite ;
- }
- @keyframes hue {
- from {transform: rotate(15deg);margin: 0px 0px;
- }
- to {
- margin: 0px 0px;transform: rotate(-15deg);
- }
- }
- .baffo{
- width:260px;
- height:5px;
- border:solid 4px #fff;
- border-color:#eee transparent transparent transparent;
- border-radius: 60%/30px 30px 0 0;
- }
- </style>
- <div id="cat">
- <div id="ears">
- <div class="ear"></div>
- <div class="ear"></div>
- </div>
- <div id="head">
- <div id="eyes">
- <div class="eye" >
- <div class="pupil" id="p1"><div class="pupil_ref"></div></div>
- </div>
- <div class="eye" >
- <div class="pupil" id="p2"><div class="pupil_ref"></div></div>
- </div>
- </div>
- <div id="nose"></div>
- <div id="baffidx">
- <div class="baffo"></div>
- <div class="baffo"></div>
- <div class="baffo"></div>
- </div>
- <div id="baffisx">
- <div class="baffo"></div>
- <div class="baffo"></div>
- <div class="baffo"></div>
- </div>
- </div>
- <div id="gc">
- <div class="lyrics">
- <div class="lyric-line">
- <div class="lyric-mask"></div>
- <div class="lyric-original"></div>
- </div>
- </div>
- </div>
- <audio id="audio" src="https://cccimg.com/view.php/31d806f415397bea14fa33a3b2030f8e.mp3" autoplay loop></audio>
- <script>
- cat.onclick = () => audio.paused ? (audio.play(),ears.style.animationPlayState = 'running',p1.style.animationPlayState = 'running',p2.style.animationPlayState = 'running',baffisx.style.animationPlayState = 'running',baffidx.style.animationPlayState = 'running') : (audio.pause(),ears.style.animationPlayState = 'paused',p1.style.animationPlayState = 'paused',p2.style.animationPlayState = 'paused',baffisx.style.animationPlayState = 'paused',baffidx.style.animationPlayState = 'paused')
- </script>
- <script>
- // 歌词解析ksc歌词或lrc歌词
- const lrc = `[00:00.900]爱江山更爱美人-周华健
- [00:19.050]道不尽红尘奢恋
- [00:22.050]诉不完人间恩怨
- [00:25.830]世世代代都是缘
- [00:31.200]流着相同的血
- [00:34.200]喝着相同的水
- [00:37.980]这条路漫漫又长远
- [00:43.350]红花当然配绿叶
- [00:46.380]这一辈子谁来陪
- [00:50.160]渺渺茫茫来又回
- [00:55.500]往日情景再浮现
- [00:58.500]藕虽断了丝还连
- [01:01.890]轻叹世间事多变迁
- [01:07.620]爱江山更爱美人
- [01:13.740]哪个英雄好汉宁愿孤单
- [01:19.800]好儿郎浑身是胆
- [01:26.190]壮志豪情四海远名扬
- [01:31.950]人生短短几个秋啊
- [01:35.730]不醉不罢休
- [01:38.820]东边儿我的美人儿
- [01:41.490]那西边儿黄河流
- [01:44.850]来呀来个酒啊
- [01:46.710]啊不醉不罢休
- [01:50.880]愁情烦事别放心头
- [02:20.580]道不尽红尘奢恋
- [02:23.610]诉不完人间恩怨
- [02:27.300]世世代代都是缘
- [02:32.730]流着相同的血
- [02:35.700]喝着相同的水
- [02:39.510]这条路漫漫又长远
- [02:44.880]红花当然配绿叶
- [02:47.880]这一辈子谁来陪
- [02:51.690]渺渺茫茫来又回
- [02:57.000]往日情景再浮现
- [03:00.060]藕虽断了丝还连
- [03:03.420]轻叹世间事多变迁
- [03:09.120]爱江山更爱美人
- [03:15.240]哪个英雄好汉宁愿孤单
- [03:21.300]好儿郎浑身是胆
- [03:27.720]壮志豪情四海远名扬
- [03:33.780]人生短短几个秋啊
- [03:37.290]不醉不罢休
- [03:40.350]东边儿我的美人儿
- [03:42.960]那西边儿黄河流
- [03:46.380]来呀来个酒啊
- [03:48.270]啊不醉不罢休
- [03:52.410]愁情烦事别放心头
- [03:58.560]来呀来个酒啊
- [04:01.590]不醉不罢休
- [04:04.590]愁情烦事别放心头
- `;
- const audio = document.getElementById('audio');
- const lyrics = parseLyrics(lrc);
- const lyricMask = document.querySelector('.lyric-mask');
- const lyricOriginal = document.querySelector('.lyric-original');
- let currentIndex = -1;
- let currentLyric = null;
- // 解析歌词(支持两种格式)
- function parseLyrics(lrcText) {
- const lyrics = [];
- if (lrcText.includes('karaoke.add')) {
- const lineRegex = /karaoke\.add\('([^']+)', '([^']+)', '([^']+)', '([^']+)'\);/g;
- let match;
- while ((match = lineRegex.exec(lrcText)) !== null) {
- const startTime = timeToMs(match[1]);
- const endTime = timeToMs(match[2]);
- const text = match[3].replace(/\[|\]/g, '').trim();
- const durations = match[4].split(',').map(Number);
- if (text) {
- lyrics.push({startTime, endTime, text, durations});
- }
- }
- }
- else if (lrcText.includes('[')) {
- const lines = lrcText.split('\n').filter(line => line.trim());
- lines.forEach((line, index) => {
- const timeMatch = line.match(/\[(\d+:\d+\.\d+)\]/);
- if (timeMatch) {
- const timeStr = timeMatch[1];
- const text = line.replace(/\[.*?\]/, '').trim();
- if (text) {
- const startTime = timeToMs(timeStr);
- const nextLine = lines[index + 1];
- const nextTimeMatch = nextLine ? nextLine.match(/\[(\d+:\d+\.\d+)\]/) : null;
- const endTime = nextTimeMatch ? timeToMs(nextTimeMatch[1]) : startTime + 5000;
- lyrics.push({
- startTime,
- endTime,
- text,
- durations: calculateCharDurations(text, startTime, endTime)
- });
- }
- }
- });
- }
- return lyrics;
- }
- function calculateCharDurations(text, startTime, endTime) {
- const totalDuration = endTime - startTime;
- const charCount = text.length;
- const baseDur = Math.floor(totalDuration / charCount);
- const durations = new Array(charCount).fill(baseDur);
- const remainder = totalDuration % charCount;
- for (let i = 0; i < remainder; i++) {
- durations[i]++;
- }
- return durations;
- }
- function timeToMs(timeStr) {
- const parts = timeStr.split(':');
- const minutes = parseInt(parts[0], 10);
- const secondsAndMs = parts[1].split('.');
- const seconds = parseInt(secondsAndMs[0], 10);
- const ms = parseInt(secondsAndMs[1] || 0, 10);
- return minutes * 60 * 1000 + seconds * 1000 + ms;
- }
- function getCurrentLyricIndex(lyrics, currentTimeMs) {
- for (let i = 0; i < lyrics.length; i++) {
- if (currentTimeMs >= lyrics[i].startTime && currentTimeMs <= lyrics[i].endTime) {
- return i;
- }
- }
- return -1;
- }
- function updateLyricDisplay(index) {
- if (index < 0 || index >= lyrics.length) return;
- currentIndex = index;
- currentLyric = lyrics[index];
- lyricOriginal.textContent = currentLyric.text;
- lyricMask.textContent = currentLyric.text;
- lyricMask.style.width = '0%';
- }
- function updateLyricMask(currentTimeMs) {
- if (!currentLyric) return;
- const lyricStartTime = currentLyric.startTime;
- const elapsed = currentTimeMs - lyricStartTime;
- const totalDuration = currentLyric.durations.reduce((sum, d) => sum + d, 0);
- let charIndex = 0;
- let accumulatedTime = 0;
- for (let i = 0; i < currentLyric.durations.length; i++) {
- accumulatedTime += currentLyric.durations[i];
- if (elapsed <= accumulatedTime) {
- charIndex = i + 1;
- break;
- }
- }
- if (elapsed >= totalDuration) {
- charIndex = currentLyric.text.length;
- }
- charIndex = Math.min(charIndex, currentLyric.text.length);
- const tempSpan = document.createElement('span');
- tempSpan.style.visibility = 'hidden';
- tempSpan.style.position = 'absolute';
- tempSpan.style.fontSize = '50px';
- tempSpan.style.fontWeight = '800';
- document.body.appendChild(tempSpan);
- const visibleText = currentLyric.text.substring(0, charIndex);
- tempSpan.textContent = visibleText;
- const width = tempSpan.offsetWidth;
- document.body.removeChild(tempSpan);
- lyricMask.style.width = `${width}px`;
- }
- // 监听更新歌词
- audio.addEventListener('timeupdate', () => {
- const currentTimeMs = audio.currentTime * 1000;
- const index = getCurrentLyricIndex(lyrics, currentTimeMs);
- if (index !== currentIndex) {
- updateLyricDisplay(index);
- }
- updateLyricMask(currentTimeMs);
- });
- updateLyricDisplay(0);
- </script>
- </td></tr></table>
复制代码 |
|