Skip to content

Commit 166d143

Browse files
author
Weera Wu
committed
Ignore touch on the center of the slide
1 parent 69de268 commit 166d143

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

index.html

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,19 @@
230230
nextTheme: function() {
231231
state.setTheme((state.theme + 1) % Object.keys(Theme).length);
232232
},
233-
touchType: function() {
233+
getTouchDirection: function(x, width) {
234+
if (!x || !width) {
235+
return null;
236+
}
237+
if (x > width * 2 / 3) {
238+
return TouchDirection.RIGHT;
239+
} else if (x > width / 2) {
240+
return TouchDirection.CENTER;
241+
} else {
242+
return TouchDirection.LEFT;
243+
}
244+
},
245+
getTouchType: function() {
234246
if (!state.touch.start) {
235247
return null;
236248
}
@@ -287,10 +299,8 @@
287299
return;
288300
}
289301
var touch = event.touches[0];
290-
var pageCenter = document.body.clientWidth / 2;
291-
state.setTouch(
292-
touch.pageX < pageCenter ? TouchDirection.LEFT : TouchDirection.RIGHT
293-
);
302+
var direction = state.getTouchDirection(touch.pageX, document.body.clientWidth);
303+
state.setTouch(direction);
294304
},
295305
handleTouchmove: function(event) {
296306
event.preventDefault();
@@ -301,7 +311,7 @@
301311
if (event.touches.length > 0) {
302312
return;
303313
}
304-
var type = state.touchType();
314+
var type = state.getTouchType();
305315
var direction = state.touch.direction;
306316
if (type === TouchType.HOLD) {
307317
state.nextTheme();

0 commit comments

Comments
 (0)