Skip to content

Commit 41e6e00

Browse files
committed
fix page
1 parent 0b83af3 commit 41e6e00

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

07-Ping-Pong-Game/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
<head>
55
<title>Ping Pong Game</title>
6-
<meta name="viewport" content="user-scalable=no">
6+
<meta name="viewport" content="user-scalable=no maximum-scale=1.0">
7+
78
<!-- Add the Bootstrap CSS file -->
89
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
910

07-Ping-Pong-Game/script.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ function actionStart(e) {
346346
//判断是鼠标左键点击还是触摸
347347
var leftPt = { pageX: canvas.width, pageY: 0 }, rightPt = { pageX: 0, pageY: 0 };
348348

349-
if (e.touches) {//如果是触摸
349+
if (e.touches && e.touches.length >1) {//如果是触摸
350350
e.touches.forEach(element => {//记录左半边,最左边的点
351351
if (element.pageX - canvas.offsetLeft < canvas.width / 2) {
352352
leftPt = element.pageX < leftPt.pageX ? element : leftPt;
@@ -357,7 +357,13 @@ function actionStart(e) {
357357
if (touchYstartLeft == null) { touchYstartLeft = leftPt.pageY; }
358358
if (touchYstartRight == null) { touchYstartRight = rightPt.pageY; }
359359
return;
360-
} else {//如果是鼠标 touchXstart等于鼠标的x坐标
360+
} else if(e.touches && e.touches.length == 1) {//如果是单点触摸
361+
if (e.touches[0].pageX - canvas.offsetLeft < canvas.width / 2) {
362+
if (touchYstartLeft == null) { touchYstartLeft = e.touches[0].pageY; }
363+
} else {
364+
if (touchYstartRight == null) { touchYstartRight = e.touches[0].pageY; }
365+
}
366+
}else {//如果是鼠标 touchXstart等于鼠标的x坐标
361367
if (e.pageX - canvas.offsetLeft < canvas.width / 2) {
362368
if (touchYstartLeft == null) { touchYstartLeft = e.pageY; }
363369
} else {
@@ -384,7 +390,7 @@ function actionMove(e) {
384390
//e.preventDefault();
385391
var distLeft, distRight, leftPt, rightPt;
386392
//判断是鼠标左键点击还是触摸
387-
if (e.touches) {
393+
if (e.touches && e.touches.length > 1) {//如果是触摸
388394
e.touches.forEach(element => {
389395
if (element.pageX - canvas.offsetLeft < canvas.width / 2) {
390396
leftPt = element.pageX < leftPt.pageX ? element : leftPt;
@@ -405,7 +411,24 @@ function actionMove(e) {
405411
if (rightPaddleY < 0) rightPaddleY = 0;
406412
}
407413

408-
} else {//如果是鼠标 dist等于鼠标的x坐标x相对touchXstart的移动距离
414+
} else if(e.touches && e.touches.length == 1) {//如果是单点触摸
415+
if (e.touches[0].pageX - canvas.offsetLeft < canvas.width / 2) {
416+
if (touchYstartLeft != null) {
417+
distLeft = e.touches[0].pageY - touchYstartLeft;
418+
leftPaddleY = previousPositionLeft + distLeft;
419+
if (leftPaddleY + paddleHeight > canvas.height) leftPaddleY = canvas.height - paddleHeight;
420+
if (leftPaddleY < 0) leftPaddleY = 0;
421+
}
422+
} else {
423+
if (touchYstartRight != null) {
424+
distRight = e.touches[0].pageY - touchYstartRight;
425+
rightPaddleY = previousPositionRight + distRight;
426+
if (rightPaddleY + paddleHeight > canvas.height) rightPaddleY = canvas.height - paddleHeight;
427+
if (rightPaddleY < 0) rightPaddleY = 0;
428+
}
429+
}
430+
431+
}else {//如果是鼠标 dist等于鼠标的x坐标x相对touchXstart的移动距离
409432
if (e.pageX - canvas.offsetLeft < canvas.width / 2) {
410433
if (touchYstartLeft != null) {
411434
distLeft = e.pageY - touchYstartLeft;

07-Ping-Pong-Game/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
flex-direction: column;
44
align-items: center;
55
justify-content: center;
6+
max-height: 75vh;
67
}
78

89
.button {
@@ -36,3 +37,7 @@
3637
canvas {
3738
background: #000;
3839
}
40+
body {
41+
overscroll-behavior-y: contain;
42+
max-height: 80vh;
43+
}

0 commit comments

Comments
 (0)