-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbainian.js
328 lines (290 loc) · 7.92 KB
/
bainian.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
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
let pageAll = document.getElementsByClassName("page");
var pageH = document.getElementById("box").offsetHeight;//页面高度
let myMusic = document.getElementById("music");
let bgm = document.getElementById("bgm");
let startY, endY, val = 0;
let curPage = 0; //当前页索引
let nextPage = 1;//下一页索引
let ifDown = false;//是否按下鼠标
let ifOK = true;//翻页是否结束
let playBgm = false;//首次点击屏幕播放音乐
//bgm播放暂停
bgm.addEventListener("click", function () {
if (myMusic.paused) {//已停止
myMusic.play();
bgm.style.animationPlayState = "running"
} else {
myMusic.pause();
bgm.style.animationPlayState = "paused"
}
})
//播放音乐
document.addEventListener("click", function (e) {
if (!playBgm && myMusic.paused) {//播放音乐
playBgm = true;
myMusic.play();
bgm.style.animationPlayState = "running"
}
setTimeout(function () {
fp();
}, 800)
$(".dianhuo").animate({
left: "34%"
}, 800)
$("#dian").hide();
})
//移动端翻页
document.addEventListener("touchstart", function (e) {
if (ifOK) {
ifDown = true;
ifOK = false;
startY = e.touches[0].pageY;
}
})
document.addEventListener("touchmove", function (e) {
if (!ifDown) {
return;
}
endY = e.touches[0].pageY;
val = startY - endY;
moveF();
})
document.addEventListener("touchend", function (e) {
if (!ifDown) {//没按下鼠标
return;
}
console.log("mouseup", val)
ifDown = false;//鼠标没点击
pageF();
})
//鼠标点击事件 pc端 翻页
document.addEventListener("mousedown", function (e) {
if (ifOK) {//上一次翻页已结束
ifDown = true;
ifOK = false;
console.log("mousedown", e.offsetY)
startY = e.offsetY;
}
})
document.addEventListener("mousemove", function (e) {
if (!ifDown) {//没按下鼠标
return;
}
endY = e.offsetY;
val = startY - endY;
moveF();
})
document.addEventListener("mouseup", function (e) {
if (!ifDown) {//没按下鼠标
return;
}
console.log("mouseup", val)
ifDown = false;//鼠标没点击
pageF();
})
//判断上翻还是下翻
function pageF() {
//可以翻了
if (Math.abs(val) > 60) {
startF();
} else {//还原不翻
pageAll[nextPage].classList.remove("active");
pageAll[nextPage].style.transform = "translateY(0px)";
clearF();
}
}
//还原
function clearF() {
val = 0;
startY = 0;
endY = 0;
ifOK = true;//翻页结束
console.log("结束", ifOK)
}
//开始翻页
function startF() {
if (val > 0) {//上翻
val += 15;
let a = pageH - val;
if (a <= 0) {
setCur();
} else {
pageAll[nextPage].style.transform = "translateY(" + a + "px)";
window.requestAnimationFrame(startF);
}
} else {
val -= 15;
let a = -(pageH + val);
if (a >= 0) {//翻页完成
setCur();
} else {
pageAll[nextPage].style.transform = "translateY(" + a + "px)";
window.requestAnimationFrame(startF);
}
}
}
//翻页完成 设置当前页面
function setCur() {
pageAll[nextPage].style.transform = "translateY(0px)";
pageAll[curPage].classList.remove("current");
curPage = nextPage;//当前页索引修改
pageAll[nextPage].classList.remove("active");
pageAll[curPage].classList.add("current");
clearF();
}
//移动
function moveF() {
nextPage = curPage;
let h;//移动
if (val > 0) {//最后一页 上翻 返回第一页
if (curPage < pageAll.length - 1) {
nextPage++;
} else {
nextPage = 0;
}
h = pageH - val;
} else {
//第一页 下翻 返回最后一页
if (curPage != 0) {
nextPage--;
} else {
nextPage = pageAll.length - 1;
}
h = - (pageH + val);
}
pageAll[nextPage].classList.add("active");
pageAll[nextPage].style.transform = "translateY(" + h + "px)";
}
//下雪
//随机数
function randNum(min, max) {
return min + Math.random() * (max - min);
}
//雪花
class Snowflake {
constructor() {
this.x = 0;
this.y = 0;
this.vx = 0;
this.vy = 0;
this.radius = 0;
this.alpha = 0;
this.reset();
}
//重置
reset() {
this.x = randNum(0, window.innerWidth);
this.y = randNum(0, -window.innerHeight);
this.vx = randNum(-3, 3);
this.vy = randNum(2, 5);
this.radius = randNum(2, 6);
this.alpha = randNum(0.4, 0.9);
}
//移动
update() {
this.x += this.vx;
this.y += this.vy;
if (this.y + this.radius > window.innerHeight) {
this.reset();
}
}
}
//雪
class Snow {
constructor() {
this.canvas = document.createElement("canvas");
this.ctx = this.canvas.getContext("2d");
document.body.appendChild(this.canvas);
window.addEventListener("resize", () => this.onResize());
this.onResize();
this.updateF = this.update.bind(this);
requestAnimationFrame(this.updateF);
this.createSnowflakes();
}
onResize() {
this.width = window.innerWidth;
this.height = window.innerHeight;
this.canvas.width = this.width;
this.canvas.height = this.height;
}
createSnowflakes() {
const num = window.innerWidth / 3;
this.snowflakes = [];
for (let s = 0; s < num; s++) {
this.snowflakes.push(new Snowflake());
}
}
update() {
this.ctx.clearRect(0, 0, this.width, this.height);
for (let flake of this.snowflakes) {
flake.update();
this.ctx.save();
this.ctx.fillStyle = "#FFF";
this.ctx.beginPath();
this.ctx.arc(flake.x, flake.y, flake.radius, 0, Math.PI * 2);
this.ctx.closePath();
this.ctx.globalAlpha = flake.alpha;
this.ctx.fill();
this.ctx.restore();
}
requestAnimationFrame(this.updateF);
}
}
new Snow();
//放炮
var $body = $('body');
var $bp = $body.find('.bianpao');
var $bomb = $body.find('.bomb');
var $bpmp3 = $body.find('#bianpao');
var speed = 20;
var fpFlag = false;
function fp() {
if (fpFlag) {
return;
}
var end = false;
var shuang = true;
fpFlag = true;
var top = ($bomb.position().top >= 460 || !$bomb.position().top) ? 460 : $bomb.position().top;
timer = setInterval(function () {
$(".dianhuo").hide();
var bombClassName = 'bomb';
var height = $bp.height();
if (end) {//放炮结束
clearInterval(timer);
$bomb.hide();
$(".bgm").show();
setTimeout(function () {
$bpmp3[0].pause();
$(".bp-box").animate({
opacity: '0'
});
//翻页放炮
setTimeout(function () {
val = 1;//上翻
startF();
}, 4000)
}, 500);
} else {
if (height % 2 == 0) {
$bomb.removeClass('bomb2').addClass('bomb1').show();
$bp.removeClass('bianpao2').addClass('bianpao1');
} else {
$bomb.removeClass('bomb1').addClass('bomb2').show();
$bp.removeClass('bianpao1').addClass('bianpao2');
}
top = $bomb.position().top;
$bomb.css('top', top - speed);
let h = height - speed;
if (h < 0) {
shuang = !shuang;
h = shuang ? 1 : 0;
setTimeout(function () {
end = true;
}, 1000)
}
$bp.css('height', h);
$bpmp3[0].play();
}
}, 100);
}