Skip to content

Instantly share code, notes, and snippets.

@skle
Created March 9, 2015 14:49
Show Gist options
  • Select an option

  • Save skle/0d817ea2285269db8867 to your computer and use it in GitHub Desktop.

Select an option

Save skle/0d817ea2285269db8867 to your computer and use it in GitHub Desktop.
Disable body scroll on iOS, enable scroll on scrollable elements
$(document).on('touchmove',function(e)
{
e.preventDefault();
});
$(document).on('touchstart', '.scroller', function(e)
{
this.startScrollY = e.originalEvent.touches[0].screenY;
this.mayScroll = false;
});
$(document).on('touchmove', '.scroller', function(e)
{
if (this.mayScroll == false)
{
var iDelta = (this.startScrollY - e.originalEvent.touches[0].screenY);
if (this.scrollTop == 0 && iDelta < 0) /* allready on top */
{
return;
}
else if ((this.scrollTop+this.clientHeight) == this.scrollHeight && iDelta > 0) /* allready on bottom */
{
return;
}
else
{
this.mayScroll = true;
}
}
e.stopPropagation();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment