-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
209 lines (192 loc) · 4.47 KB
/
index.html
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>七夕快乐</title>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<style>
*{
margin:0;
padding:0;
}
audio {
display:none;
}
body{
background-color: #f6f5ee;
}
.center{
text-align: center;
}
/* head */
.head{
position: relative;
margin:100px auto;
width:100px;
height:100px;
}
.img{
width:100%;
height:100%;
border-radius:50%;
box-shadow: 0 3px 5px #b0b0b0;
background:url(head.jpg) center center no-repeat;
cursor:pointer;
}
/* loading */
.loading{
-webkit-animation:loading 5s infinite linear;
animation:loading 5s infinite linear;
}
@-webkit-keyframes loading{
0% {
-webkit-transform: rotateZ(0deg);
}
100% {
-webkit-transform: rotateZ(360deg);
}
}
@keyframes loading{
0% {
transform: rotateZ(0deg);
}
100% {
transform: rotateZ(360deg);
}
}
/* button */
.btn {
opacity:0;
cursor:pointer;
font-size: 15px;
padding: 14px 20px 11px;
font-weight: 500;
color: #fff;
text-transform: uppercase;
border-radius: 3px;
background: #1abc9c;
margin-top: -3px;
box-shadow: 0px 3px 0px 0px #148f77;
}
.btn:active{
opacity: 0.8;
-webkit-transition:opacity 0.3s;
transition:opacity 0.3s;
}
/* tooltip */
.tooltip{
position: absolute;
z-index: 3;
top: -34px;
left: 71px;
padding: 10px;
background: white;
color: #3d464d;
font: 500 13px/14px arial;
border-radius: 4px;
white-space: nowrap;
box-shadow: 0px 1px 1px rgba(0,0,0,0.2);
min-width: 97px;
text-align: center;
border: 1px solid #edefed;
opacity:0;
}
.tooltip:before {
left: 0;
bottom: 5px;
position: absolute;
margin-top: -17px;
margin-left: -10px;
content: '';
width: 0;
height: 0;
border-style: solid;
border-width: 0 9.5px 10px 9.5px;
border-color: transparent transparent white transparent;
}
.show{
opacity:1;
-webkit-transition: opacity 2s;
transition: opacity 2s;
}
</style>
</head>
<body>
<div class="head">
<div class="img" id="img"></div>
<div class="tooltip" id="tooltip">hi</div>
</div>
<div class="center">
<a class="btn" id="jokeBtn">讲笑话</a>
<a class="btn" id="musicBtn">唱个曲</a>
</div>
<audio id="audio" controls></audio>
<script>
var audio = document.getElementById("audio"),
jokeBtn = document.getElementById("jokeBtn"),
musicBtn = document.getElementById("musicBtn"),
img = document.getElementById("img"),
tooltip = document.getElementById("tooltip"),
timer,
status;
var ready=function(){
jokeBtn.setAttribute("class", "btn show");
musicBtn.setAttribute("class", "btn show");
audio.onended=function() {
img.setAttribute("class", "img");
tooltip.innerHTML="随便再点个~";
status=0;
};
audio.onplaying = function() {
img.setAttribute("class", "img");
tooltip.innerHTML="点我暂停";
status=1;
};
jokeBtn.onclick = function() {
audio.ended=true;
audio.src = "http://test-10004444.file.myqcloud.com/"+Math.round(Math.random()*5)+".mp3";
audio.play();
};
musicBtn.onclick = function() {
audio.ended=true;
audio.src = "http://test-10004444.file.myqcloud.com/m"+Math.round(Math.random()*2)+".mp3";
audio.play();
};
img.onclick=function(){
if(!status)return;
if(audio.paused){
audio.play();
tooltip.innerHTML="点我暂停";
}else{
audio.pause();
tooltip.innerHTML="点我继续";
}
};
};
/* 解决移动端不能自动播放音频问题 */
timer=setTimeout(function(){
img.setAttribute("class", "img");
tooltip.innerHTML="hello,七夕快乐~";
ready();
},1000);
audio.onwaiting = function() {
img.setAttribute("class", "img loading");
tooltip.innerHTML="正在加载...";
timer && clearTimeout(timer);
};
audio.onplaying = function() {
img.setAttribute("class", "img");
tooltip.innerHTML="hello,七夕快乐~";
};
audio.onended=function(){
tooltip.innerHTML="听我讲个笑话吧~";
ready();
};
audio.src = "http://test-10004444.file.myqcloud.com/hello.mp3";
audio.play();
tooltip.setAttribute("class", "tooltip show");
</script>
</body>
</html>