<style>
.bk1 {position:relative; left:0px; width:1000px; height:600px; margin:30px auto; box-shadow:0px 0px 20px 10px #008000; display: grid; place-items:center; overflow: hidden; z-index: 0; border:2px #cccccc solid;}
@keyframes aniAct0{
0%{opacity:0.8;transform:scale(1.05);}
50%{opacity:1;transform:scale(1.5);}
100%{opacity:0.8;transform:scale(1.05);}
}
/** .bk2 改作 .lm12 , .lm* 共有设置集中在#c1 上**/
#c1 {position:relative; left:0px; width:996px; height:596px; margin:0px auto; overflow:hidden; border:0px #cccccc solid;background-repeat:no-repeat;background-position:center;background-size:cover;}
.lm12 {background-image:url('https://pic1.imgdb.cn/item/63357df216f2c2beb16d8984.jpg');animation:aniAct0 20s infinite;}
.lm0 {background-image:url('https://pic.imgdb.cn/item/6331055716f2c2beb14a95c4.jpg');animation:aniAct0 20s infinite;}
.lm1 {background-image:url('https://pic1.imgdb.cn/item/6334361f16f2c2beb14abe1d.jpg');animation:aniAct0 7s infinite;}
.lm2 {background-image:url('https://pic1.imgdb.cn/item/6334361f16f2c2beb14abe17.jpg');animation:aniAct0 5s infinite;}
.lm3 {background-image:url('https://pic1.imgdb.cn/item/633436a416f2c2beb14b3cc7.jpg');animation:aniAct0 6s infinite;}
.lm4 {background-image:url('https://pic1.imgdb.cn/item/6334366116f2c2beb14afe81.jpg');animation:aniAct0 6s infinite;}
.lm5 {background-image:url('https://pic1.imgdb.cn/item/633436d916f2c2beb14b6b8c.jpg');animation:aniAct0 5s infinite;}
.lm6 {background-image:url('https://pic1.imgdb.cn/item/6334366116f2c2beb14afe8d.jpg');animation:aniAct0 6s infinite;}
.lm7 {background-image:url('https://pic1.imgdb.cn/item/6334366116f2c2beb14afe86.jpg');animation:aniAct0 12s infinite;}
.lm8 {background-image:url('https://pic1.imgdb.cn/item/6334366116f2c2beb14afe7e.jpg');animation:aniAct0 5s infinite;}
.lm9 {background-image:url('https://tx2.a.yximgs.com/udata/music/music_ee57b90fc4f54e1aa906187ad69959550.jpg');
animation:aniAct0 6s infinite;}
.lm10 {background-image:url('https://pic1.imgdb.cn/item/6334361f16f2c2beb14abe12.jpg');animation:aniAct0 6s infinite;}
.lm11 {background-image:url('https://pic1.imgdb.cn/item/6334366116f2c2beb14afe94.jpg');animation:aniAct0 6s infinite;}
/** 下面是与LRC处理的设置 */
#mplayer {position:absolute;z-index:2; bottom:0px; left:10px; width:100px; height: 30px; display: grid; place-items: center; cursor: pointer; }
#mplayer:hover #btnwrap, #mplayer:hover #prog { transform: translateY(var(--yy)); }
#mplayer:hover #btnwrap {background: linear-gradient(to top right, red, green); border-radius: 50%; opacity: .75; }
#btnwrap, #prog {position: absolute; display:grid; place-items:center; transition: .5s; }
#btnwrap { --yy: -15px; width:40px; height:40px; transform:rotate(45deg); border:1px solid tan; border-radius:6px; opacity: .25; }
#btnplay {width:20px; height:20px; transform: translateX(3px); background: #eee; clip-path: polygon(0 0, 0% 100%, 100% 50%); }
#btnpause { width: 2px; height: 20px; border-style: solid; border-width: 0px 4px; border-color: transparent #eee; display: none; }
#prog {--yy:20px; width:100px; height:16px; border-radius:10px; background: linear-gradient(90deg, orange, red 100%, transparent 0); border: 1px solid gray; font: normal 14px / 16px sans-serif; color: #333; opacity: .75; }
#lrc { z-index:2;position: absolute; top:520px; font:bold 3.2em sans-serif; color:rgba(255,255,255,.99); text-shadow:1px 1px 1px #000; --motion: cover2; --tt: 1s; --state: running; }
#lrc::before { position:absolute; content:attr(data-lrc); width: 0; height: 100%; left: 0px; top: 0px; color: rgba(255,0,0,.9); overflow: hidden; white-space: nowrap; 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%; } }
/** 下面是与雄鹰有关的设置 */
#mpic {position: absolute; transform: rotateY(0deg); left: 0; top: 0; width: 120px; offset-distance: 0; offset-path: path("M 0 0 Q 300 150, 512 180 T 1024 110"); animation: move 8s linear infinite ;z-index : 10;}
@keyframes move { to { offset-distance: 100%; } }
#mpic1 {position: absolute; transform: rotateX(180deg); left: 0; top: 0; width: 100px; offset-distance: 0; offset-path: path("M 1024 100 Q 512 160, 300 100 T 0 0"); animation: move1 8s linear infinite ;z-index : 10;}
@keyframes move1 { to { offset-distance: 100%; } }
</style>
<div id="c3" class ="bk1">
<div id="c1" class ="lm12"></div>
<img id="mpic" alt="" src="https://pic.imgdb.cn/item/6330fcbb16f2c2beb143688d.gif" />
<img id="mpic1" alt="" src="https://pic.imgdb.cn/item/6330fcbb16f2c2beb143688d.gif" />
<div id="lrc" data-lrc=" "> </div>
<div id="mplayer">
<div id="btnwrap"><span id="btnplay"></span><span id="btnpause"></span></div>
<div id="prog">00:00 | 00:00</div>
</div>
</div>
<script>
let mKey = 0, mSeek = false, mFlag = true, aud = new Audio();
let lrcAr = [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,];
aud.src = 'https://music.163.com/song/media/outer/url?id=1883829929.mp3';
aud.autoplay = true;
aud.loop = false; // 不循环播放
btnwrap.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());
// 背景切换的代码
let picTime = [
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,
];
let pIdx = 0; ciObj = document.getElementById("c1");
aud.onended = function() {pIdx = 0;this.play();}
aud.addEventListener('timeupdate', () => {
prog.style.background= 'linear-gradient(90deg, green, red ' + aud.currentTime / aud.duration * 100 + '%, snow 0)';
prog.innerText = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);
for(j=0; j<lrcAr.length; j++) {
if(aud.currentTime >= lrcAr) {
// 背景切换的控制代码----------
if(pIdx <= picTime.length- 1 && aud.currentTime >= picTime) {
ciObj.className = picTime;
pIdx++;
}
//------------------------------
if(mKey === j) showLrc(lrcAr);
else continue;
}
}
});
let mState = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none', lrc.style.setProperty('--state', 'paused')) : (btnplay.style.display = 'none', btnpause.style.display = 'block', lrc.style.setProperty('--state', 'running'));
let showLrc = (time) => {
let name = mFlag ? 'cover1' : 'cover2';
lrc.innerHTML = lrc.dataset.lrc = lrcAr;
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) {
mKey = j - 1;
break;
}
}
if(mKey <0) mKey = 0;
if(mKey > lrcAr.length - 1) mKey = lrcAr.length - 1;
let time = lrcAr - (aud.currentTime - lrcAr);
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>
195400 发表于 2022-10-1 11:23
.bk1 {position:relative; left:0px; width:1000px; height:600px; margin:30px auto; box-shadow:0px...
谢谢老师指教!老师修改后的代码简洁多了,我的思路不行呀,且我没有事先设计,而是想到哪就在哪加的代码。BK1、BK2是原想的两个外框,LM是我在JS中变换的类名,我只会条件语句,所以代码;P就那样的写啦。 寒冬残荷 发表于 2022-10-1 17:31
谢谢老师指教!老师修改后的代码简洁多了,我的思路不行呀,且我没有事先设计,而是想到哪就在哪加的代码 ...
还用了 switch ……case …… :lol 195400 发表于 2022-10-1 17:57
还用了 switch ……case ……
判断我就会if...else和switch ……case ……,所以我看不懂你们写的lrc 处理代码,不知你们是如何判断歌词唱到嗜哪里了…… 寒冬残荷 发表于 2022-10-1 20:59
判断我就会if...else和switch ……case ……,所以我看不懂你们写的lrc 处理代码,不知你们是如何判断歌 ...
if …………
else if …………
else if ……
………………
else
和 switch …… case ……
同样的效果 如何判断歌词唱到哪里了
currentTime和 每行歌词前面的时间比较就知道了
页:
1
[2]