mirror of
https://github.com/yv1ing/MollyBlog.git
synced 2025-09-16 14:53:45 +08:00
new: Added music collection page
This commit is contained in:
33
templates/default/assets/js/music.js
Normal file
33
templates/default/assets/js/music.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const bodyWrap = document.getElementById('body-wrap');
|
||||
const playerWrap = document.getElementById('music-player-wrap');
|
||||
|
||||
syncWidth();
|
||||
window.addEventListener('resize', syncWidth);
|
||||
|
||||
function syncWidth() {
|
||||
playerWrap.style.width =window.getComputedStyle(bodyWrap).width;
|
||||
}
|
||||
|
||||
function play(name, singer, coverSrc, musicSrc, lyricSrc) {
|
||||
fetch(lyricSrc)
|
||||
.then((res) => {
|
||||
return res.text();
|
||||
})
|
||||
.then((data) => {
|
||||
const musicData = musicSrc;
|
||||
const lyricData = data;
|
||||
|
||||
MollyPlayer({
|
||||
music: {
|
||||
src: musicData,
|
||||
lrc: lyricData,
|
||||
cover: coverSrc,
|
||||
title: name,
|
||||
author: singer,
|
||||
loop: true,
|
||||
},
|
||||
target: '#music-player',
|
||||
autoplay: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user