Add swiping
All checks were successful
Deploy new version of the application / Deploy Application (push) Successful in 3s

This commit is contained in:
2025-10-23 17:27:45 +02:00
parent d97e432695
commit a2d80210bf
2 changed files with 39 additions and 1 deletions

View File

@@ -163,5 +163,4 @@
</div> </div>
</body> </body>
<script src="script.js"></script> <script src="script.js"></script>
</html> </html>

View File

@@ -183,6 +183,45 @@ window.mouseover = () => {
console.log('User active, resetting idle timer.'); 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(); addInProgress();
init(); init();