Skip to content

Instantly share code, notes, and snippets.

@awatson1978
Last active June 2, 2017 22:12
Show Gist options
  • Save awatson1978/de39d8d6ed0ed6a7d9e2 to your computer and use it in GitHub Desktop.
Save awatson1978/de39d8d6ed0ed6a7d9e2 to your computer and use it in GitHub Desktop.
Scrolling
// Disables scroll except for allowed elements that prevent touchmove event propagation
$(document).on('touchmove', function(event){
event.preventDefault();
});
// Elements which are allowed touchmove event (by stopping event propagation to document)
$('body').on('touchmove','.scrollable, nav', function(event) {
event.stopPropagation();
});
// Prevents scrollable elements from ever reaching the end of scroll, and thus prevents scroll overflow on ipad
$('body').on('touchstart','.scrollable', function(event) {
if (event.currentTarget.scrollTop === 0) {
event.currentTarget.scrollTop = 1;
}
else if (event.currentTarget.scrollHeight === event.currentTarget.scrollTop + event.currentTarget.offsetHeight) {
event.currentTarget.scrollTop -= 1;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment