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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#