Add swiping
All checks were successful
Deploy new version of the application / Deploy Application (push) Successful in 3s
All checks were successful
Deploy new version of the application / Deploy Application (push) Successful in 3s
This commit is contained in:
@@ -163,5 +163,4 @@
|
||||
</div>
|
||||
</body>
|
||||
<script src="script.js"></script>
|
||||
|
||||
</html>
|
||||
39
script.js
39
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();
|
||||
|
||||
Reference in New Issue
Block a user