找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
楼主: 老谟深虑

学习亚伦老师的代码音画《走在冷雨里》

[复制链接]

45

主题

1374

回帖

9320

积分

镇海神笔

积分
9320
发表于 2024-12-2 10:18:35 | 显示全部楼层 IP:湖北
老谟深虑 发表于 2024-12-2 09:49
老师我调了一下,你看看可以不?


<div style="position: absolute; left:60px;width:100%;margin-top:120px;">
<style type="text/css">
.mnBox {
        top: 10px;
        position: relative;
        background: #333 url('https://cccimg.com/view.php/e68c0b4f52ae99ad435dd77ade371a98.jpg') no-repeat center/cover;
        height: 720px;
        width: 1286px;
        left:20px;overflow: hidden;
        margin:10px auto;
        border: 1px solid;
        box-shadow: 0px 0px 0px 2px tan;
}

试试这样能不能居中

30

主题

7217

回帖

3万

积分

超级版主

积分
37613
发表于 2024-12-2 10:26:12 | 显示全部楼层 IP:福建厦门
老谟深虑 发表于 2024-12-2 09:31
这个还是看不见吧,这就说明你的电脑对亚伦老师的代码你行。

听得到,看不见图像!癌症!

208

主题

1万

回帖

6万

积分

超级版主

积分
63088
发表于 2024-12-2 10:50:56 | 显示全部楼层 IP:
悦耳动听的歌曲,令人心情愉快!为老谟版主精彩音画佳作点赞!
上午好!

302

主题

8833

回帖

6万

积分

版主

积分
64483
发表于 2024-12-2 11:04:01 | 显示全部楼层 IP:美国
欣赏老师的代码音画《走在冷雨里》,界面很美,歌曲好听,点赞!

449

主题

2万

回帖

10万

积分

超级版主

积分
106711
 楼主| 发表于 2024-12-2 11:20:20 | 显示全部楼层 IP:亚太地区
起个网名好难 发表于 2024-12-2 10:18
.mnBox {
        top: 10px;
        position: relative;

        按着老师的改了,我这边看是偏右了,你再看看。

68

主题

2万

回帖

8万

积分

超级版主

积分
85863
发表于 2024-12-2 11:21:12 | 显示全部楼层 IP:河北
歌曲选择得好,至于图像偏左,应该纠正一下。

449

主题

2万

回帖

10万

积分

超级版主

积分
106711
 楼主| 发表于 2024-12-2 11:23:10 | 显示全部楼层 IP:亚太地区
咕咚来了 发表于 2024-12-2 11:21
歌曲选择得好,至于图像偏左,应该纠正一下。

       我按难难老师的指导改的。

45

主题

1374

回帖

9320

积分

镇海神笔

积分
9320
发表于 2024-12-2 11:26:22 | 显示全部楼层 IP:湖北
老谟深虑 发表于 2024-12-2 11:20
按着老师的改了,我这边看是偏右了,你再看看。

不好意思, 确实偏右了

68

主题

2万

回帖

8万

积分

超级版主

积分
85863
发表于 2024-12-2 11:27:21 | 显示全部楼层 IP:河北
本帖最后由 咕咚来了 于 2024-12-2 11:35 编辑

<div style="position: absolute; ;width:100%;margin-top:120px;">
<style type="text/css">
.mnBox {
        
        position: relative;
        background: #333 url('https://cccimg.com/view.php/e68c0b4f52ae99ad435dd77ade371a98.jpg') no-repeat center/cover;
        height: 720px;
        width: 1286px;
        overflow: hidden;
        margin:10px auto;
        border: 1px solid;
        box-shadow: 0px 0px 0px 2px tan;
}

.rain {
        width: 1px;
        height: 8px;
        top: -20px;
        left: 400px;
        background: #eee;
        position: relative;
        display: block;
        animation: rain 0.5s linear infinite;
}

.rain::before, .rain::after{
        content: "";
        position: absolute;
        left: 10px;
        top: -120px;
        width: 1px;
        height: 15px;
        background: #eee;
}



.circle {
        position:absolute;
        width: 3px;
        height: 1px;
        left: 85px;
        top: 90%;
        background:none;
        border: 1px solid #FFF;
        border-radius: 50%;
        animation:circle 2s ease-out infinite;
}

@keyframes circle {
        0% { width:0; height:0; }
        50% { opacity:0.1; width:2%; height:2%; }
        60% { opacity:0.2; width:2%; height:2%; }
        100% { opacity:0; width:2%; height:2%; }
}

@keyframes rain {
        0% { opacity:0.5; }
        100% { opacity:0.5; top:40%;  }
}
#player {
        position: absolute;z-index: 40;
        left:35px;
        bottom: 50px;
        width: 150px;
        height: 150px;
         opacity: 1;
        transition: .4s;
display: grid;
        place-items: center;
        --sp1: 0; --sp2: 1;
}
#player::before, #player::after {
        position: absolute;
        content: '';
        cursor: pointer;
        transition: .4s;
}
#player::before {width: 150px;height: 150px;background:url()no-repeat center/cover;
        opacity: var(--sp1);}
#player::after {width: 150px;height: 150px;background:url()no-repeat center/cover;
        opacity: var(--sp2);}
#phone{position: absolute;z-index: 5;width:60px;content: attr(data-lrc);margin-left:87%;margin-top:90px;display:inline-block;text-align: center;  font:400 3.5em/1em 华文隶书; color:rgba(255,255,255,0.7);background:-webkit-linear-gra**nt(-180deg,rgba(255,255,255,0) 100px,rgba(255,255,255,1) 80px,rgba(255,255,255,1) 640px,rgba(255,255,255,0) 800px) 40px 0px no-repeat;-webkit-background-clip:text;filter:drop-shadow(#000 1px 0 0)drop-shadow(#000 0 1px 0)drop-shadow(#000 -1px 0 0) drop-shadow(#000 0 -1px  0);}

#lrc {--state: paused;--motion: cover2;--tt: 2s;--bg: linear-gra**nt(0deg, #880000, #880000, #880000);
position: absolute;z-index: 6;left: 50%; top: 80%;transform: translate(-50%);font:normal 3.5em 华文隶书; font-weight:400;color: #000080;white-space: pre;-webkit-background-clip: text;filter:drop-shadow(#FFFFFF 1px 0 0)drop-shadow(#FFFFFF 0 1px 0)drop-shadow(#FFFFFF -1px 0 0) drop-shadow(#FFFFFF 0 -1px  0);}
#lrc::before {position: absolute;content: attr(data-lrc);width: 100%; height: 100%;color: transparent;overflow: hidden;white-space: pre;background: var(--bg);clip-path: inset(0 100% 0 0);-webkit-background-clip: text;animation: var(--motion) var(--tt) linear forwards;animation-play-state: var(--state);}
@keyframes cover1{ to { clip-path: inset(0 0 0 0); } }@keyframes cover2 { to { clip-path: inset(0 0 0 0); } }
</style>
<div  class="mnBox"  id="mnBox">
<div id="player" title="/" ></div>
<div data-lrc="" id="lrc"></div>
  
<div id="phone"><p style="font:400 0.8em/1.2em 华文隶书; width:25px;margin-left:12px;text-align: center;"></p></div>
<span class="rain"></span>
<span class="circle"></span>
</div>
<audio id="aud" src="https://file.uhsea.com/2411/a84e33c0ac730a4a013f1fff084c539dOX.mp3" autoplay loop>
<script >
function rain() {
        var str = "";
        for(i=0; i<50; i++) {
                var l = Math.ceil(Math.random()*1286);
                str += "<span class='rain' style='left:" + l +"px;'></span>";
        }
        for(j=0;j<40; j++){
                var k1 = Math.ceil(Math.random()*100);
                var k2 = Math.round(Math.random()*40+70);
                str += "<span class='circle' style='left:" + k1 +"%;top:" + k2 +"%;'></span>";
        }
        document.getElementById('mnBox').innerHTML += str;
}

rain();

let raindrops = mnBox.querySelectorAll('.rain');
let rainpops = mnBox.querySelectorAll('.circle');
let rainState = () => {
        aud.paused ? (raindrops.forEach( drop => {drop.style.animationPlayState='paused'}) , rainpops.forEach( pop => {pop.style.animationPlayState='paused'}))
                                : (raindrops.forEach( drop => {drop.style.animationPlayState='running'}) , rainpops.forEach( pop => {pop.style.animationPlayState='running'}));
}


let mState = () => {rainState();aud.paused ? (player.style.setProperty('--sp1','1'), player.style.setProperty('--sp2','0')) : (player.style.setProperty('--sp1','0'), player.style.setProperty('--sp2','1'))};

aud.addEventListener('play', () => mState());
aud.addEventListener('pause', () => mState());
player.addEventListener('click', () => aud.paused ? aud.play() : aud.pause());

</script>
<script >
(function() {
/*原始lrc歌词*/
let lrcStr = `[00:00.000]走在冷雨里(Live 合唱版)-艺凌
[00:02.802]词曲:隔壁老陈
[00:05.604]编曲:李胜华
[00:08.406]合唱:毅然合唱团
[00:11.208]混音:毅然音乐
[00:14.010]制作人:陈金文
[00:16.812]LRC:老谟深虑
[00:19.620]走在冷雨里
[00:24.600]苦苦找寻往日的甜蜜
[00:30.930]冷风一阵阵
[00:35.880]吹不散我心中的忧虑
[00:42.210]为什么你要狠心地离去
[00:47.940]我不明白错在了哪里
[00:53.550]如果我伤了你
[00:56.400]不是我故意
[00:59.190]我真的爱你不想放弃
[01:02.010]只想和你在一起
[01:04.830]求求你不要不要再生气
[01:10.440]快快回到我的怀抱里
[01:33.060]走在冷雨里
[01:37.980]苦苦找寻往日的甜蜜
[01:44.310]凄风一阵阵
[01:49.260]吹不散我心中的忧虑
[01:55.650]为什么你要把我来抛弃
[02:01.320]你给我太多太多的回忆
[02:06.960]如果我伤了你
[02:09.780]不是我故意
[02:12.630]我真的爱你真的想你
[02:15.420]只盼情缘能再续
[02:18.240]求求你不要不要再怀疑
[02:23.880]我的生命里不能没有你
[02:52.140]为什么你要把我来抛弃
[02:57.810]你给我太多太多的回忆
[03:03.420]如果我伤了你
[03:06.270]不是我故意
[03:09.090]我真的爱你真的想你
[03:11.910]只盼情缘能再续
[03:14.670]求求你不要不要再怀疑
[03:20.370]我的生命里不能没有你
`;
/*变量 :mKey - 当前歌词索引;mFlag :调用关键帧动画索引;averAdd :平均值补偿*/
let mKey = 0, mFlag = true, averAdd = 0.3;

/*函数 :获取每句歌词用时,歌词用时若超过平均值则取平均值,最后一句歌词则取平均值*/
let lrcTime = (ar) => {
        let tmpAr = [];
        for(j = 0; j <ar.length - 1; j ++) {
                if(j !== ar.length - 1) tmpAr[j] = parseFloat((ar[j+1][0] - ar[j][0]).toFixed(1));
        }
        let aver = parseInt(tmpAr.reduce((a,b) => a + b) / (tmpAr.length - 1)) + averAdd;
        tmpAr.push(aver);
        tmpAr.forEach((item,key) => {
                ar[key][2] = item > aver ? aver : item;
        });
        return ar;
};

/*函数 :从原始lrc歌词获取信息并存入 n*3 数组*/
let getLrcAr = (text) => {
        let lrcAr = [];
        let calcRule = [60,1,0.001];
        for(x of text.split('\n')) {
                let ar = [];
                let re = /\d+[\.:]\d+([\.:]\d+)?/g;
                let geci = x.replace(re,'');
                if(geci) {
                        geci = geci.replace(/[\[\]\'\"\t,]s?/g,'');
                        let time = x.match(re);
                        if(time != null) {
                                for(y of time) {
                                        let tmp = y.match(/\d+/g);
                                        let sec = 0;
                                        for(z in tmp) sec += tmp[z] * calcRule[z];
                                        ar[0] = [parseFloat(sec.toFixed(2)), geci];
                                        lrcAr.push(ar[0]);
                                }
                        }
                }
        }
        lrcAr.sort((a,b)=> a[0] - b[0]);
        return(lrcTime(lrcAr));
};

/*函数 :模拟显示同步歌词*/
let showLrc = (time) => {
        let name = mFlag ? 'cover1' : 'cover2';
        lrc.innerHTML = lrcAr[mKey][1];
        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;
};

/*函数 :处理当前歌词索引 mKey*/
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;
}

/*函数 :关键帧动画状态切换*/
let mState = () => aud.paused ? (lrc.style.setProperty('--state','paused'),player.style.animationPlayState = 'paused') : (lrc.style.setProperty('--state','running'),player.style.animationPlayState = 'running');

/*监听播放进度*/
aud.addEventListener('timeupdate', () => {
        for (j = 0; j < lrcAr.length; j++) {
                if (aud.currentTime >= lrcAr[j][0]) {
                        cKey = j;
                        if (mKey === j) showLrc(lrcAr[j][2]);
                        else continue;
                }
        }
});
aud.addEventListener('pause', () => mState());/*监听暂停事件*/
aud.addEventListener('play', () => mState());/*监听播放事件*/
aud.addEventListener('seeked', () => calcKey());/*监听查询事件*/
let lrcAr = getLrcAr(lrcStr); /*获得歌词数组*/
})();
</script>
<script>
var ph=document.getElementById("phone");
var otime=null;
var num=-100;
function tomove(){  if(!aud.paused){
        otime=setInterval(function (){
                num+=10;
                if(num==1100)
                {
                        num=-100;
                        clearInterval(otime);
                }
                ph.style.backgroundPosition=num+"px 0px";
               
                },20)}
        }
tomove();
setInterval(function(){
        tomove();        
},2000);
</script>
</div>
<div style="height:960px;"></div>


还是代码有问题,发现其中有许多方括号了吗,那是不应该出现的HTML代码中的。重新换新代码,把图片的音乐加入,应该没问题。勾选禁用链接识别。


45

主题

1374

回帖

9320

积分

镇海神笔

积分
9320
发表于 2024-12-2 11:29:40 | 显示全部楼层 IP:湖北
本帖最后由 起个网名好难 于 2024-12-2 18:30 编辑

  1. <style type="text/css">
  2. .mnBox {
  3. position: absolute;
  4. background: #333 url('https://cccimg.com/view.php/e68c0b4f52ae99ad435dd77ade371a98.jpg') no-repeat center/cover;
  5. height: 620px;
  6. width: 1286px;
  7. overflow: hidden;
  8. margin-top:90px;
  9. border: 1px solid;
  10. box-shadow: 0px 0px 0px 2px tan;
  11. left:50%;transform: translate(-50%);
  12. }
  13. .rain {
  14. width: 1px;
  15. height: 8px;
  16. top: -20px;
  17. left: 400px;
  18. background: #eee;
  19. position: relative;
  20. display: block;
  21. animation: rain 0.5s linear infinite;
  22. }
  23. .rain::before, .rain::after{
  24. content: "";
  25. position: absolute;
  26. left: 10px;
  27. top: -120px;
  28. width: 1px;
  29. height: 15px;
  30. background: #eee;
  31. }
  32. .circle {
  33. position:absolute;
  34. width: 3px;
  35. height: 1px;
  36. left: 85px;
  37. top: 90%;
  38. background:none;
  39. border: 1px solid #FFF;
  40. border-radius: 50%;
  41. animation:circle 2s ease-out infinite;
  42. }
  43. @keyframes circle {
  44. 0% { width:0; height:0; }
  45. 50% { opacity:0.1; width:2%; height:2%; }
  46. 60% { opacity:0.2; width:2%; height:2%; }
  47. 100% { opacity:0; width:2%; height:2%; }
  48. }
  49. @keyframes rain {
  50. 0% { opacity:0.5; }
  51. 100% { opacity:0.5; top:40%; }
  52. }
  53. #player {
  54. position: absolute;z-index: 40;
  55. left:35px;
  56. bottom: 50px;
  57. width: 150px;
  58. height: 150px;
  59. opacity: 1;
  60. transition: .4s;
  61. display: grid;
  62. place-items: center;
  63. --sp1: 0; --sp2: 1;
  64. }
  65. #player::before, #player::after {
  66. position: absolute;
  67. content: '';
  68. cursor: pointer;
  69. transition: .4s;
  70. }
  71. #player::before {width: 150px;height: 150px;background:url(https://cccimg.com/view.php/98bdbaeb6a57278824a651eb414e2188.png)no-repeat center/cover;
  72. opacity: var(--sp1);}
  73. #player::after {width: 150px;height: 150px;background:url(https://cccimg.com/view.php/98bdbaeb6a57278824a651eb414e2188.png)no-repeat center/cover;
  74. opacity: var(--sp2);}
  75. #phone{position: absolute;z-index: 5;width:60px;content: attr(data-lrc);margin-left:87%;margin-top:90px;display:inline-block;text-align: center; font:400 3.5em/1em 华文隶书; color:rgba(255,255,255,0.7);background:-webkit-linear-gra**nt(-180deg,rgba(255,255,255,0) 100px,rgba(255,255,255,1) 80px,rgba(255,255,255,1) 640px,rgba(255,255,255,0) 800px) 40px 0px no-repeat;-webkit-background-clip:text;filter:drop-shadow(#000 1px 0 0)drop-shadow(#000 0 1px 0)drop-shadow(#000 -1px 0 0) drop-shadow(#000 0 -1px 0);}
  76. #lrc {--state: paused;--motion: cover2;--tt: 2s;--bg: linear-gra**nt(0deg, #880000, #880000, #880000);
  77. position: absolute;z-index: 6;left: 50%; top: 80%;transform: translate(-50%);font:normal 3.5em 华文隶书; font-weight:400;color: #000080;white-space: pre;-webkit-background-clip: text;filter:drop-shadow(#FFFFFF 1px 0 0)drop-shadow(#FFFFFF 0 1px 0)drop-shadow(#FFFFFF -1px 0 0) drop-shadow(#FFFFFF 0 -1px 0);}
  78. #lrc::before {position: absolute;content: attr(data-lrc);width: 100%; height: 100%;color: transparent;overflow: hidden;white-space: pre;background: var(--bg);clip-path: inset(0 100% 0 0);-webkit-background-clip: text;animation: var(--motion) var(--tt) linear forwards;animation-play-state: var(--state);}
  79. @keyframes cover1{ to { clip-path: inset(0 0 0 0); } }@keyframes cover2 { to { clip-path: inset(0 0 0 0); } }
  80. </style>
  81. <div class="mnBox" id="mnBox">
  82. <div id="player" title="/" ></div>
  83. <div data-lrc="" id="lrc"></div>
  84. <div id="phone"><p style="font:400 0.8em/1.2em 华文隶书; width:25px;margin-left:12px;text-align: center;"></p></div>
  85. <span class="rain"></span>
  86. <span class="circle"></span>
  87. <audio id="aud" src="https://file.uhsea.com/2411/a84e33c0ac730a4a013f1fff084c539dOX.mp3" autoplay loop ></audio>
  88. </div>
  89. <div style="height:960px;"></div>
  90. <script >
  91. function rain() {
  92. var str = "";
  93. for(i=0; i<50; i++) {
  94. var l = Math.ceil(Math.random()*1286);
  95. str += "<span class='rain' style='left:" + l +"px;'></span>";
  96. }
  97. for(j=0;j<40; j++){
  98. var k1 = Math.ceil(Math.random()*100);
  99. var k2 = Math.round(Math.random()*40+70);
  100. str += "<span class='circle' style='left:" + k1 +"%;top:" + k2 +"%;'></span>";
  101. }
  102. document.getElementById('mnBox').innerHTML += str;
  103. }
  104. rain();
  105. let raindrops = mnBox.querySelectorAll('.rain');
  106. let rainpops = mnBox.querySelectorAll('.circle');
  107. let rainState = () => {
  108. aud.paused ? (raindrops.forEach( drop => {drop.style.animationPlayState='paused'}) , rainpops.forEach( pop => {pop.style.animationPlayState='paused'}))
  109. : (raindrops.forEach( drop => {drop.style.animationPlayState='running'}) , rainpops.forEach( pop => {pop.style.animationPlayState='running'}));
  110. }
  111. let mState = () => {rainState();aud.paused ? (player.style.setProperty('--sp1','1'), player.style.setProperty('--sp2','0')) : (player.style.setProperty('--sp1','0'), player.style.setProperty('--sp2','1'))};
  112. aud.addEventListener('play', () => mState());
  113. aud.addEventListener('pause', () => mState());
  114. player.addEventListener('click', () => aud.paused ? aud.play() : aud.pause());
  115. </script>
  116. <script >
  117. (function() {
  118. /*原始lrc歌词*/
  119. let lrcStr = `[00:00.000]走在冷雨里(Live 合唱版)-艺凌
  120. [00:02.802]词曲:隔壁老陈
  121. [00:05.604]编曲:李胜华
  122. [00:08.406]合唱:毅然合唱团
  123. [00:11.208]混音:毅然音乐
  124. [00:14.010]制作人:陈金文
  125. [00:16.812]LRC:老谟深虑
  126. [00:19.620]走在冷雨里
  127. [00:24.600]苦苦找寻往日的甜蜜
  128. [00:30.930]冷风一阵阵
  129. [00:35.880]吹不散我心中的忧虑
  130. [00:42.210]为什么你要狠心地离去
  131. [00:47.940]我不明白错在了哪里
  132. [00:53.550]如果我伤了你
  133. [00:56.400]不是我故意
  134. [00:59.190]我真的爱你不想放弃
  135. [01:02.010]只想和你在一起
  136. [01:04.830]求求你不要不要再生气
  137. [01:10.440]快快回到我的怀抱里
  138. [01:33.060]走在冷雨里
  139. [01:37.980]苦苦找寻往日的甜蜜
  140. [01:44.310]凄风一阵阵
  141. [01:49.260]吹不散我心中的忧虑
  142. [01:55.650]为什么你要把我来抛弃
  143. [02:01.320]你给我太多太多的回忆
  144. [02:06.960]如果我伤了你
  145. [02:09.780]不是我故意
  146. [02:12.630]我真的爱你真的想你
  147. [02:15.420]只盼情缘能再续
  148. [02:18.240]求求你不要不要再怀疑
  149. [02:23.880]我的生命里不能没有你
  150. [02:52.140]为什么你要把我来抛弃
  151. [02:57.810]你给我太多太多的回忆
  152. [03:03.420]如果我伤了你
  153. [03:06.270]不是我故意
  154. [03:09.090]我真的爱你真的想你
  155. [03:11.910]只盼情缘能再续
  156. [03:14.670]求求你不要不要再怀疑
  157. [03:20.370]我的生命里不能没有你
  158. `;
  159. /*变量 :mKey - 当前歌词索引;mFlag :调用关键帧动画索引;averAdd :平均值补偿*/
  160. let mKey = 0, mFlag = true, averAdd = 0.3;
  161. /*函数 :获取每句歌词用时,歌词用时若超过平均值则取平均值,最后一句歌词则取平均值*/
  162. let lrcTime = (ar) => {
  163. let tmpAr = [];
  164. for(j = 0; j <ar.length - 1; j ++) {
  165. if(j !== ar.length - 1) tmpAr[j] = parseFloat((ar[j+1][0] - ar[j][0]).toFixed(1));
  166. }
  167. let aver = parseInt(tmpAr.reduce((a,b) => a + b) / (tmpAr.length - 1)) + averAdd;
  168. tmpAr.push(aver);
  169. tmpAr.forEach((item,key) => {
  170. ar[key][2] = item > aver ? aver : item;
  171. });
  172. return ar;
  173. };
  174. /*函数 :从原始lrc歌词获取信息并存入 n*3 数组*/
  175. let getLrcAr = (text) => {
  176. let lrcAr = [];
  177. let calcRule = [60,1,0.001];
  178. for(x of text.split('\n')) {
  179. let ar = [];
  180. let re = /\d+[\.:]\d+([\.:]\d+)?/g;
  181. let geci = x.replace(re,'');
  182. if(geci) {
  183. geci = geci.replace(/[\[\]\'"\t,]s?/g,'');
  184. let time = x.match(re);
  185. if(time != null) {
  186. for(y of time) {
  187. let tmp = y.match(/\d+/g);
  188. let sec = 0;
  189. for(z in tmp) sec += tmp[z] * calcRule[z];
  190. ar[0] = [parseFloat(sec.toFixed(2)), geci];
  191. lrcAr.push(ar[0]);
  192. }
  193. }
  194. }
  195. }
  196. lrcAr.sort((a,b)=> a[0] - b[0]);
  197. return(lrcTime(lrcAr));
  198. };
  199. /*函数 :模拟显示同步歌词*/
  200. let showLrc = (time) => {
  201. let name = mFlag ? 'cover1' : 'cover2';
  202. lrc.innerHTML = lrcAr[mKey][1];
  203. lrc.dataset.lrc = lrcAr[mKey][1];
  204. lrc.style.setProperty('--motion', name);
  205. lrc.style.setProperty('--tt', time + 's');
  206. lrc.style.setProperty('--state', 'running');
  207. mKey += 1;
  208. mFlag = !mFlag;
  209. };
  210. /*函数 :处理当前歌词索引 mKey*/
  211. let calcKey = () => {
  212. for (j = 0; j < lrcAr.length; j++) {
  213. if (aud.currentTime <= lrcAr[j][0]) {
  214. mKey = j - 1;
  215. break;
  216. }
  217. }
  218. if (mKey < 0) mKey = 0;
  219. if (mKey > lrcAr.length - 1) mKey = lrcAr.length - 1;
  220. let time = lrcAr[mKey][2] - (aud.currentTime - lrcAr[mKey][0]);
  221. showLrc(time);
  222. };
  223. /*格式化时间信息*/
  224. let toMin = (val) => {
  225. if (!val) return '00:00';
  226. val = Math.floor(val);
  227. let min = parseInt(val / 60),
  228. sec = parseFloat(val % 60);
  229. if (min < 10) min = '0' + min;
  230. if (sec < 10) sec = '0' + sec;
  231. return min + ':' + sec;
  232. }
  233. /*函数 :关键帧动画状态切换*/
  234. let mState = () => aud.paused ? (lrc.style.setProperty('--state','paused'),player.style.animationPlayState = 'paused') : (lrc.style.setProperty('--state','running'),player.style.animationPlayState = 'running');
  235. /*监听播放进度*/
  236. aud.addEventListener('timeupdate', () => {
  237. for (j = 0; j < lrcAr.length; j++) {
  238. if (aud.currentTime >= lrcAr[j][0]) {
  239. cKey = j;
  240. if (mKey === j) showLrc(lrcAr[j][2]);
  241. else continue;
  242. }
  243. }
  244. });
  245. aud.addEventListener('pause', () => mState());/*监听暂停事件*/
  246. aud.addEventListener('play', () => mState());/*监听播放事件*/
  247. aud.addEventListener('seeked', () => calcKey());/*监听查询事件*/
  248. let lrcAr = getLrcAr(lrcStr); /*获得歌词数组*/
  249. })();
  250. </script>
  251. <script>
  252. var ph=document.getElementById("phone");
  253. var otime=null;
  254. var num=-100;
  255. function tomove(){ if(!aud.paused){
  256. otime=setInterval(function (){
  257. num+=10;
  258. if(num==1100)
  259. {
  260. num=-100;
  261. clearInterval(otime);
  262. }
  263. ph.style.backgroundPosition=num+"px 0px";
  264. },20)}
  265. }
  266. tomove();
  267. setInterval(function(){
  268. tomove();
  269. },2000);
  270. </script>
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|离退休论坛 ( 浙B2-20100176 )

GMT+8, 2025-5-20 08:23 , Processed in 0.092134 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表