根据慕课网上视频,写的。

img

记录一下:
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0,
minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no"/>
<title>慕课贺春</title>

<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>
<div class="music">
<img src="img/music_pointer.png">
<img id="music" class="play" src="img/music_disc.png">
</div>
<div class="page" id="page1">
<div class="bg"></div>
<div class="p1_lantern">点击屏幕<br />开启好运2016</div>
<div class="p1_immoc"></div>
<div class="p1_words">2016年慕课网新年特献</div>
</div>
<div class="page" id="page2">
<div class="p2_bg_loading"></div>
<div class="bg"></div>
<div class="p2_circle"></div>
<div class="p2_2016"></div>
</div>
<div class="page" id="page3">
<div class="bg"></div>
<div class="p3_logo"></div>
<div class="p3_title"></div>
<div class="p3_second"></div>
<div class="p3_first"></div>
<div class="p3_blessing"></div>
</div>

<audio autoplay="true">
<source src="http://www.imooc.com/activity/project/project1/audio/happynewyear.mp3" type="audio/mpeg">

</audio>
</body>
</html>

css:

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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
/* all tag */

* {
margin: 0;
padding: 0;
border: none;
font-size: 1.5625vw;
font-family: "microsoft yahei";
}

html,
body {
height: 100%;
overflow: hidden;
}


/**
* music tag
*/

.music {
width: 15vw;
height: 15vw;
border: 4px solid #ef1639;
position: fixed;
top: 3vh;
right: 4vw;
z-index: 5;
border-radius: 50%;
background: #fff;
}

.music > img:first-of-type {
position: absolute;
top: 24%;
right: 2.5%;
width: 28.421%;
z-index: 1;
}

.music > img:last-of-type {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
width: 79%;
z-index: 0;
}

.music > img.play {
-webkit-animation: music_disc 4s linear infinite;
-moz-animation: music_disc 4s linear infinite;
-ms-animation: music_disc 4s linear infinite;
-o-animation: music_disc 4s linear infinite;
animation: music_disc 4s linear infinite;
}

@-webkit-keyframes music_disc {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
transform: rotate(360deg);
}
}

@keyframes music_disc {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
transform: rotate(360deg);
}
}


/**
* page tag
*/

.page {
position: absolute;
width: 100%;
height: 100%;
}

.page > .bg {
position: absolute;
z-index: -1;
height: 100%;
width: 100%;
}


/**
* page1 tag
*/

#page1 {
display: block;
}

#page1 > .bg {
background: url(../img/p1_bg.jpg) no-repeat center center;
background-size: 100%;
}

#page1 > .p1_lantern {
position: absolute;
top: -3.4%;
right: 0;
left: 0;
margin: auto;
background: url(../img/p1_lantern.png) no-repeat center bottom;
background-size: 100%;
width: 45vw;
height: 71.2vh;
font-size: 3.506rem;
color: #fff;
padding-top: 31vh;
text-align: center;

-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box;
}

#page1 > .p1_lantern:before {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
content: "";
margin: auto;
width: 30vw;
height: 30vw;
background: #D60B3B;
opacity: .5;
border-radius: 50%;
-webkit-box-shadow: 0 0 10vw 10vw #D60B3B;
-moz-box-shadow: 0 0 10vw 10vw #D60B3B;
-ms-box-shadow: 0 0 10vw 10vw #D60B3B;
-o-box-shadow: 0 0 10vw 10vw #D60B3B;
box-shadow: 0 0 10vw 10vw #D60B3B;
-webkit-animation: p1_lantern .5s infinite alternate;
-moz-animation: p1_lantern .5s infinite alternate;
-o-animation: p1_lantern .5s infinite alternate;
animation: p1_lantern .5s infinite alternate;
}

@-webkit-keyframes p1_lantern {
0% {
opacity: .5;
-webkit-transform: scale(.8, .8);
transform: scale(.8, .8);
}
100% {
opacity: 1;
}
}

@keyframes p1_lantern {
0% {
opacity: .5;
-webkit-transform: scale(.8, .8);
transform: scale(.8, .8);
}
100% {
opacity: 1;
}
}

#page1 > .p1_immoc {
position: absolute;
right: 0;
bottom: 0;
left: 0;
background: url(../img/p1_imooc.png) no-repeat center center;
background-size: 100%;
width: 27.656vw;
height: 30.656vh;
margin: auto;
}

#page1 > .p1_words {
font-size: 2.314rem;
position: absolute;
right: 0;
left: 0;
bottom: 23px;
text-align: center;
color: #231815;
}


/**
* page2 tag
*/

#page2 {
display: none;
-webkit-transition: .5s;
transition: .5s;
}

#page2.fadeOut{
opacity: .3;
-webkit-transform: translate(0, -100%);
transform: translate(0, -100%);
}

#page2 > .p2_bg_loading{
z-index: 4;
background: #ef1639;
-webkit-animation: p2_bg_loading 1s linear forwards;
animation: p2_bg_loading 1s linear forwards;
}

@-webkit-keyframes p2_bg_loading{
from{
opacity: 1;
}
to{
opacity: 0;
}
}

@keyframes p2_bg_loading{
from{
opacity: 1;
}
to{
opacity: 0;
}
}

#page2 > .bg {
background: url(../img/p2_bg.jpg) no-repeat center center;
background-size: 100%;
}

#page2 > .p2_circle {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border-radius: 50%;
background: url(../img/p2_circle_outer.png) no-repeat center center;
background-size: 100%;
width: 59.375vw;
height: 59.375vw;
-webkit-animation: p2_circle_outter 1s linear 3s infinite;
animation: p2_circle_outter 1s linear 3s infinite;
}

@-webkit-keyframes p2_circle_outter {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(-360deg);
transform: rotate(-360deg);
}
}

@keyframes p2_circle_outter {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(-360deg);
transform: rotate(-360deg);
}
}

#page2 > .p2_circle:before {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border-radius: 50%;
content: "";
background: url(../img/p2_circle_middle.png) no-repeat center center;
background-size: 100%;
width: 45.625vw;
height: 45.625vw;
-webkit-animation: p2_circle_middle 1s linear 2s infinite;
animation: p2_circle_middle 1s linear 2s infinite;
}

@-webkit-keyframes p2_circle_middle {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(720deg);
transform: rotate(720deg);
}
}

@keyframes p2_circle_middle {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(720deg);
transform: rotate(720deg);
}
}

#page2 > .p2_circle:after {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border-radius: 50%;
content: "";
background: url(../img/p2_circle_inner.png) no-repeat center center;
background-size: 100%;
width: 39.9375vw;
height: 39.9375vw;
-webkit-animation: p2_circle_inner 1s linear 1s infinite;
animation: p2_circle_inner 1s linear 1s infinite;
}

@-webkit-keyframes p2_circle_inner {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(-1080deg);
transform: rotate(-1080deg);
}
}

@keyframes p2_circle_inner {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(-1080deg);
transform: rotate(-1080deg);
}
}

#page2 > .p2_2016 {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
background: url(../img/p2_2016.png) no-repeat center center;
background-size: 100%;
width: 27.5vw;
height: 6.24vh;
}


/**
* page3 tag
*/

#page3 {
display: none;
-webkit-transition: .5s;
transition: .5s;
}

#page3.fadeIn{
-webkit-transform: translate(0, -100%);
transform: translate(0, -100%);
}

#page3 > .bg {
background: url(../img/p3_bg.jpg) no-repeat center center;
background-size: 100%;
}

#page3 > .p3_logo {
width: 34.6875vw;
height: 6.327vh;
position: absolute;
top: 7.82vh;
right: 0;
left: 0;
margin: auto;
background: url(../img/p3_logo.png) no-repeat center center;
background-size: 100%;
}

#page3 > .p3_title {
width: 48.125vw;
height: 50vh;
position: absolute;
top: 21vh;
right: 0;
left: 0;
margin: auto;
background: url(../img/p3_title.png) no-repeat center center;
background-size: 100%;
}

#page3 > .p3_second {
width: 22.8125vw;
height: 41.652vh;
position: absolute;
top: 25.48vh;
left: 3.75vw;
background: url(../img/p3_couplet_second.png) no-repeat center center;
background-size: 100%;
}

#page3 > .p3_first {
width: 22.8125vw;
height: 41.652vh;
position: absolute;
top: 25.48vh;
right: 3.75vw;
background: url(../img/p3_couplet_first.png) no-repeat center center;
background-size: 100%;
}

#page3 > .p3_blessing {
width: 32vw;
height: 32vh;
position: absolute;
right: 0;
bottom: 3vh;
left: 0;
margin: auto;
border-radius: 50%;
background: url(../img/p3_blessing.png) no-repeat center center;
background-size: 100%;
-webkit-animation: p3_blessing 2s linear infinite;
animation: p3_blessing 2s linear infinite;
}

@-webkit-keyframes p3_blessing {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}

@keyframes p3_blessing {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}

js

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

window.onload = function(){
/*console.log("网页可见区域宽:" + document.body.clientWidth);
console.log("网页可见区域高:" + document.body.clientHeight);
console.log("网页可见区域宽(包括边线的宽):" + document.body.offsetWidth);
console.log("网页可见区域高(包括边线的高):" + document.body.offsetHeight);
console.log("网页正文全文宽:" + document.body.scrollWidth);
console.log("网页正文全文高:" + document.body.scrollHeight);
console.log("网页被卷去的高:" + document.body.scrollTop);
console.log("网页被卷去的左:" + document.body.scrollLeft);
console.log("网页正文部分上:" + window.screenTop);
console.log("网页正文部分左:" + window.screenLeft);
console.log("屏幕分辨率的宽:" + window.screen.width);
console.log("屏幕分辨率的高:" + window.screen.height);
console.log("屏幕可用工作区宽度:" + window.screen.availWidth);
console.log("屏幕可用工作区高度:" + window.screen.availHeight);*/

//获取元素
var page1 = document.getElementById("page1");
var page2 = document.getElementById("page2");
var page3 = document.getElementById("page3");

var music = document.getElementById("music");
var audio = document.getElementsByTagName("audio")[0];

//当音乐播放完停止的时候,自动停止光盘旋转效果
audio.addEventListener("ended", function(event){
music.setAttribute("class", "");
//this.style.animationPlayState = "paused";
//this.style.webkitAnimationPlayState = "paused";
}, false);

//点击音乐图标,控制音乐播放效果
/*music.onclick = function(){
if(audio.paused){
audio.play();
this.setAttribute("class","play");
//this.style.animationPlayState = "running";
//this.style.webkitAnimationPlayState = "running";
}else{
audio.pause();
this.setAttribute("class","");
//this.style.animationPlayState = "paused";
//this.style.webkitAnimationPlayState = "paused";
}
}*/

//点击音乐图标,控制音乐播放效果
music.addEventListener("touchstart", function(event){
if(audio.paused){
audio.play();
this.setAttribute("class","play");
//this.style.animationPlayState = "running";
//this.style.webkitAnimationPlayState = "running";
}else{
audio.pause();
this.setAttribute("class","");
//this.style.animationPlayState = "paused";
//this.style.webkitAnimationPlayState = "paused";
}
}, false);

//点击屏幕,开启好运2016
page1.addEventListener("touchstart", function(event){
page1.style.display = "none";
page2.style.display = "block";
page3.style.display = "block";
page3.style.top = "100%";

setTimeout(function(){
page2.setAttribute("class", "page fadeOut");
page3.setAttribute("class", "page fadeIn");
}, 5500);
}, false);
}

遇到的坑1,page3.style.top = “100%”;写成了 100% ,马丹找了好久才发现问题的所在。
遇到的坑2,引入了js,在里面写的点击事件,但是就事没有效果,经过排查,发现是上面被遮挡了,index-z 的问题。