Last active
June 2, 2017 22:12
-
-
Save awatson1978/de39d8d6ed0ed6a7d9e2 to your computer and use it in GitHub Desktop.
Scrolling
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
// 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