aboutsummaryrefslogtreecommitdiff
path: root/client/js/util
diff options
context:
space:
mode:
authorHunternif2019-04-11 07:34:32 +0700
committerHunternif2019-04-11 07:50:32 +0700
commit04e0f7f12c2f99f9fdebd24c6db54618f68ed139 (patch)
treebde477dd6dae9e1ef874a25be29313588e037eff /client/js/util
parentdd7bcdb242a44aa13388197a9c0be1c83969112d (diff)
Add swipe threshold, fix incorrect up/down detection, swipe down for random.
Diffstat (limited to 'client/js/util')
-rw-r--r--client/js/util/touch.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/client/js/util/touch.js b/client/js/util/touch.js
index 6863eb8..3a64642 100644
--- a/client/js/util/touch.js
+++ b/client/js/util/touch.js
@@ -6,6 +6,9 @@ const direction = {
UP: 'up'
};
+const thresholdX = 0.15;
+const thresholdY = 0.1;
+
function handleTouchStart(handler, evt) {
const touchEvent = evt.touches[0];
handler._xStart = touchEvent.clientX;
@@ -21,16 +24,22 @@ function handleTouchMove(handler, evt) {
const yDirection = handler._yStart - evt.touches[0].clientY;
if (Math.abs(xDirection) > Math.abs(yDirection)) {
- if (xDirection > 0) {
+ let percentSwiped = Math.abs(xDirection) / screen.width;
+ if (percentSwiped < thresholdX) {
+ return;
+ } else if (xDirection > 0) {
handler._direction = direction.LEFT;
} else {
handler._direction = direction.RIGHT;
}
} else {
- if (yDirection > 0) {
- handler._direction = direction.DOWN;
- } else {
+ let percentSwiped = Math.abs(yDirection) / screen.height;
+ if (percentSwiped < thresholdY) {
+ return;
+ } else if (yDirection > 0) {
handler._direction = direction.UP;
+ } else {
+ handler._direction = direction.DOWN;
}
}
}

© 2015 - 2026 Jakob L. Kreuze