Skip to content

Instantly share code, notes, and snippets.

@souljorje
Last active September 13, 2017 11:24
Show Gist options
  • Save souljorje/46dcb3b88658a4104f633f62856a2eb7 to your computer and use it in GitHub Desktop.
Save souljorje/46dcb3b88658a4104f633f62856a2eb7 to your computer and use it in GitHub Desktop.
Disable touch move for all elements except selected
if ( $(window).innerWidth() <= 980) {
let scrollArea = document.querySelector(".selector");
scrollArea.addEventListener("touchstart", function(event) {
this.previousClientY = event.touches[0].clientY;
});
scrollArea.addEventListener("touchmove", function(event) {
let scrollTop = this.scrollTop;
let maxScroll = this.scrollHeight - this.offsetHeight;
let currentClientY = event.touches[0].clientY;
let deltaY = this.previousClientY - currentClientY;
if ( (scrollTop === maxScroll && deltaY > 0) || (scrollTop === 0 && deltaY < 0) ) {
event.preventDefault();
}
this.previousClientY = currentClientY;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment