summaryrefslogtreecommitdiff
path: root/res/main.js
blob: 2f42d19656e4fc44bf75cf5d398fb2cc550b326e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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;
}