Categories
JavaScript Answers

How to disable scrolling in an iPhone web application with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *