From be4dbb725ca307c358b6a8ba4cd6e0c32962b8c5 Mon Sep 17 00:00:00 2001 From: Mao Date: Sun, 17 Jan 2021 17:09:15 +0000 Subject: [PATCH] Fix touch handling in the case where window.scrollX/Y > 0 Currently this breaks when user has scrolled the page. Also, this commit uses preventDefault() to keep page from scrolling when user is connecting a word. --- wordfindgame.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wordfindgame.js b/wordfindgame.js index 07366a6..5245486 100644 --- a/wordfindgame.js +++ b/wordfindgame.js @@ -102,18 +102,20 @@ * to the letter that was selected. * */ - var startTurn = function () { + var startTurn = function (evt) { $(this).addClass('selected'); startSquare = this; selectedSquares.push(this); curWord = $(this).text(); + evt.preventDefault(); }; var touchMove = function(e) { - var xPos = e.originalEvent.touches[0].pageX; - var yPos = e.originalEvent.touches[0].pageY; + var xPos = e.originalEvent.touches[0].clientX; + var yPos = e.originalEvent.touches[0].clientY; var targetElement = document.elementFromPoint(xPos, yPos); select(targetElement) + e.preventDefault(); }; var mouseMove = function() {