How to prevent native scrolling on mobile browsers
This is a simple but useful tip if you are working on web applications on mobile devices.
If you want to ignore all events that can scroll the body content, you can bind a function to the touchmove event that prevents default behavior and stop propagation of the event:
document.body.addEventListener("touchmove", function(event) {
event.preventDefault();
event.stopPropagation();
}, false);
In jQuery or similar libraries:
$(document.body).on("touchmove", function(event) {
event.preventDefault();
event.stopPropagation();
});
Written by emi420
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mobile
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#