Skip to content

Instantly share code, notes, and snippets.

@AlexMeah
Last active August 29, 2015 13:57
Show Gist options
  • Save AlexMeah/9486370 to your computer and use it in GitHub Desktop.
Save AlexMeah/9486370 to your computer and use it in GitHub Desktop.
// Allow scrolling on anything with class scrollable
$(document).on('touchstart', '.scrollable', function (event) {
var startY = event.originalEvent.touches[0].pageY;
var startTopScroll = this.scrollTop;
if (startTopScroll <= 0) {
this.scrollTop = 1;
}
if (startTopScroll + this.offsetHeight >= this.scrollHeight) {
this.scrollTop = this.scrollHeight - this.offsetHeight - 1;
}
});
$(document).on('touchmove', '.scrollable', function (event) {
if ($(this)[0].scrollHeight > $(this).outerHeight()) {
event.stopImmediatePropagation();
event.stopPropagation();
}
});
.scrollable {
overflow: scroll;
-webkit-overflow-scrolling: touch;
max-height: $height;
max-width: $width;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment