Last Updated: February 25, 2016
·
25.86K
· emi420

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();
});