diff options
Diffstat (limited to 'res/main.js')
-rw-r--r-- | res/main.js | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/res/main.js b/res/main.js new file mode 100644 index 0000000..543cd16 --- /dev/null +++ b/res/main.js @@ -0,0 +1,105 @@ + +// play music + +var currentAudio; +var currentPlay; + +function showPlayButton(cover) { + var play = cover.getElementsByClassName("play_img"); + play[0].style.display="inline"; + play[0].style.cursor="pointer"; +} + +function hidePlayButton(cover) { + var play = cover.getElementsByClassName("play_img"); + play[0].style.display="none"; +} + +function playMusic(play) { + var src = play.getAttribute("audiosrc"); + if(currentPlay != null){ + currentAudio.pause(); + hidePlayButtonSelf(currentPlay); + pauseMusic(currentPlay); + } + currentAudio = new Audio(src); + currentAudio.play(); + + currentPlay = play; + + play.src="./res/pause_cover.png"; + play.onclick = function() { + pauseMusic(play); + }; + play.onmouseleave = null; + + play.parentElement.onmouseleave = null; +} + +function pauseMusic(play) { + if(currentPlay == play){ + currentAudio.pause(); + currentPlay = null; + //hidePlayButtonSelf(play); + } + + play.src="./res/play_cover.png"; + play.onclick = function() { + playMusic(play); + } + play.onmouseleave = function() { + hidePlayButtonSelf(play); + } + + play.parentElement.onmouseleave = function() { + hidePlayButton(play.parentElement); + } +} + +function showPlayButtonSelf(play) { + play.style.display="inline"; + play.style.cursor="pointer"; +} + +function hidePlayButtonSelf(play) { + play.style.display="none"; + play.style.cursor="auto"; +} + +// + +function changeMusicListWidth () { + var music_list = document.getElementById("music_list"); + var music_outer = document.getElementById("music_outer"); + var outer_width = music_outer.offsetWidth; + music_list.style.width = Math.floor( outer_width / 120) * 120; +} + +window.onload = function() { + changeMusicListWidth(); +} + +window.onresize = function(){ + changeMusicListWidth(); +} + +// time + +function formatDate(stamp){ + var time = new Date(stamp * 1000); + var y = time.getFullYear(); //年 + var m = time.getMonth() + 1; //月 + if(m < 10){ m = '0' + m } + var d = time.getDate(); //日 + if(d < 10){ d = '0' + d } + var h = time.getHours(); //时 + if(h < 10){ h = '0' + h } + var mm = time.getMinutes(); //分 + if(mm < 10){ mm = '0' + mm } + var s = time.getSeconds(); //秒 + if(s < 10){ s = '0' + s } + var timeStr = m+"/"+d+", "+y; + //var timeStr = y+"-"+m+"-"+d +" "+h+":"+mm+":"+s; + return timeStr; +} + |