From a2d80210bf08b7ad26467d6e5f48e43e6b1fbfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Feh=C3=A9r?= Date: Thu, 23 Oct 2025 17:27:45 +0200 Subject: [PATCH] Add swiping --- index.html | 1 - script.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 1be161e..4ac4a6c 100644 --- a/index.html +++ b/index.html @@ -163,5 +163,4 @@ - \ No newline at end of file diff --git a/script.js b/script.js index 1dfbd75..eea9d72 100644 --- a/script.js +++ b/script.js @@ -183,6 +183,45 @@ window.mouseover = () => { console.log('User active, resetting idle timer.'); } +let touchstartX = 0; +let touchstartY = 0; +let touchendX = 0; +let touchendY = 0; + +window.addEventListener('touchstart', function (event) { + touchstartX = event.changedTouches[0].screenX; + touchstartY = event.changedTouches[0].screenY; +}, false); + +window.addEventListener('touchend', function (event) { + touchendX = event.changedTouches[0].screenX; + touchendY = event.changedTouches[0].screenY; + handleGesture(); +}, false); + + +function handleGesture() { + if (touchendX < touchstartX) { + if (touchendX - touchstartX < -150) { + if (currentCard === -1) return; + if (currentCard === cards.length - 1) return; + nextCard(); + } + } + + if (touchendX > touchstartX) { + if (touchendX - touchstartX > 150) { + if (currentCard <= 0) return; + previousCard(); + } + } + + if (touchendY < touchstartY) { + if (touchendY - touchstartY < -150) { + close(); + } + } +} addInProgress(); init();