【习作】乡恋
本帖最后由 相约爱晚亭 于 2022-10-28 13:37 编辑 <br /><br /><style>#papa { left: -214px; width: 1024px; height: 640px; background: #ccc url('https://s1.ax1x.com/2022/10/20/x6G9pQ.jpg') no-repeat center/cover;display: grid; place-items: center; overflow: hidden; position: relative; z-index: 1; }
#mplayer { position: absolute; left: 200px;bottom: 0; width: 300px; height: 80px; user-select: none; 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; 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: 300px; height: 16px; border-radius: 10px; background: linear-gradient(90deg, black, blue 100%, transparent 0); border: 1px solid gray; font: normal 14px / 16px sans-serif; color: olive; opacity: .75; }
#lrc { position: absolute; left: 550px; top: 30px; font: bold 2em sans-serif; color: transparent; letter-spacing: 2px; background: linear-gradient(-90deg, purple, orange) 100% 100% / 200% 200%; background-clip: text; -webkit-background-clip: text; }
#plane {position: absolute;left: 60px;top: 0;width: 100px;offset-distance: 0;offset-path: path("M0 20 Q300 80, 600 200 T1000 100");animation: move 8s linear infinite;}
@keyframes bgMove1 { from { background-position: 0 0; } to { background-position: -100% 0; } }
@keyframes bgMove2 { from { background-position: 0 0; } to { background-position: -100% 0; } }
@keyframes move { to { offset-distance: 100%;} }
</style>
<div id="papa">
<img id="plane" src="/data/attachment/forum/202209/17/192324pvmm0vvrnsds3yhd.png" alt="" />
<div id="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 lrcAr = [
['0.00', '乡 恋',1],
['0.99', '乡 恋',2],
['3.06', '作词:马靖华',3],
['6.06', '作曲:张丕基',3],
['9.06', '演唱:梦之旅合唱组合',10],
['18.82', 'LRC制作相约爱晚亭',9],
['27.55', '你的身影',5],
['32.84', '你的歌声',5],
['38.12', '永远印在我的心中',10],
['48.82', '昨天虽已消逝',5],
['54.29', '分别难相逢',5],
['59.55', '怎能忘记你的一片深情',11],
['70.16', '昨天虽已消逝',6],
['75.99', '分别难相逢',5],
['80.91', '怎能忘记你的一片深情',11],
['91.65', '★ ★ 相约爱晚亭制作 ★ ★',11],
['102.65', '★ ★ 欢迎您光临欣赏 ★ ★',10],
['112.94', '我的情爱',6],
['118.58', '我的美梦',5],
['123.56', '永远留在你的怀中',10],
['134.02', '明天就要来临',6],
['139.66', '却难得和你相逢',5],
['144.88', '只有风儿送去我的深情',11],
['155.56', '明天就要来临',5],
['160.88', '却难得和你相逢',5],
['166.15', '只有风儿送去我的深情',11],
['176.86', '啦...啦...啦.. 啦..',11],
['187.86', '啦...啦...啦.. 啦..',10],
['198.19', '明天就要来临',6],
['203.99', '却难得和你相逢',5],
['208.82', '只有风儿送去我的深情',17],
['222.82', '欢迎您光临欣赏',3]
];
let mKey = 0, mFlag = true;
let aud = new Audio();
aud.src = 'https://365.tf/disk/tf/1667017945.mp3';
aud.autoplay = true;
aud.loop = true;
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());
aud.addEventListener('timeupdate', () => {
prog.style.background= 'linear-gradient(90deg, black, blue ' + 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(mKey === j) showLrc(lrcAr);
else continue;
}
}
});
let mState = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none', lrc.style.animationPlayState = 'paused') : (btnplay.style.display = 'none', btnpause.style.display = 'block', lrc.style.animationPlayState = 'running');
let showLrc = (time) => {
lrc.style.animation = (mFlag ? 'bgMove1 ' : 'bgMove2 ') + time + 's linear forwards';
lrc.innerHTML = lrcAr;
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;
let mtime = lrcAr - (aud.currentTime - lrcAr);
showLrc(mtime);
}
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>
<br><br><br><br><br><br><br><br><br><br>
这个制作看这听舒服,好棒哈 谢谢黑黑老师代码分享。 画面淡雅清秀,看起来有一种很安静的感觉。 欣赏、点赞! 马黑黑 发表于 2022-10-20 23:57
这个制作看这听舒服,好棒哈
谢谢老师的支持和鼓励! 梦油 发表于 2022-10-21 09:02
画面淡雅清秀,看起来有一种很安静的感觉。
谢谢您的关注和支持! 起个网名好难 发表于 2022-10-21 18:31
欣赏、点赞!
谢谢老师的支持和鼓励!试用了老师设计的LRC格式转换工具,效果很好! 相约爱晚亭 发表于 2022-10-21 21:01
谢谢老师的支持和鼓励!
{:4_191:} 相约爱晚亭 发表于 2022-10-21 21:01
谢谢您的关注和支持!
别客气 很清爽的画面,歌词同步做得漂亮。欣赏爱晚亭好帖{:4_187:}
页:
[1]