Created
January 5, 2023 04:10
-
-
Save bramses/9576769f1329c751180c80bf43466038 to your computer and use it in GitHub Desktop.
swipe left to open menu; swipe right to close it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swipe left on mobile to open menu | |
let touchstartX = 0; | |
let touchendX = 0; | |
function checkDirection() { | |
// check if greater than 100px | |
// if swipe right close menu | |
if (touchendX < touchstartX && touchstartX - touchendX > 100) { | |
document | |
.querySelector(".published-container") | |
.classList.remove("is-left-column-open"); | |
} | |
if (touchendX > touchstartX && touchendX - touchstartX > 100) { | |
document | |
.querySelector(".published-container") | |
.classList.add("is-left-column-open"); | |
} | |
} | |
document.addEventListener("touchstart", (e) => { | |
touchstartX = e.changedTouches[0].screenX; | |
}); | |
document.addEventListener("touchend", (e) => { | |
touchendX = e.changedTouches[0].screenX; | |
checkDirection(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment