Sometimes, we want to disable scrolling in an iPhone web application with JavaScript.
In this article, we’ll look at how to disable scrolling in an iPhone web application with JavaScript.
How to disable scrolling in an iPhone web application with JavaScript?
To disable scrolling in an iPhone web application with JavaScript, we prevent the default behavior when we touch the screen.
For instance, we write
document.addEventListener("touchstart", (e) => {
e.preventDefault();
});
to listen to the touchstart event on the document
with addEventListener
.
In the event listener, we call e.preventDefault
to stop scrolling when we touch the screen.
Conclusion
To disable scrolling in an iPhone web application with JavaScript, we prevent the default behavior when we touch the screen.