How to prevent scrolling the page on iOS Safari 15

Rik Schennink: If we show a modal on iOS we need to prevent events inside the modal from interacting with the page behind the modal. On a previous episode of “Fun with Safari” we could use preventDefault() on the touchmove event but on iOS 15 that no longer works. Here we go. The solution lies …


This content originally appeared on Bram.us and was authored by Bramus!

Rik Schennink:

If we show a modal on iOS we need to prevent events inside the modal from interacting with the page behind the modal. On a previous episode of “Fun with Safari” we could use preventDefault() on the touchmove event but on iOS 15 that no longer works. Here we go.

The solution lies in preventing pointermove while the modal is shown.

Using Rik’s code, here’s a demo on CodePen:

See the Pen
How to prevent scrolling the page on iOS Safari 15
by Bramus (@bramus)
on CodePen.

Rik does set overflow to hidden on the html element there. Most likely this will interfere with classic scrollbars. This can be countered with some scrollbar-gutter: stable;

In the near future we should be able to drop Rik’s code, and simply use the overscroll-behavior CSS property (which I’ve covered here before back in 2017) for this. And by “near future” I really do mean soon: there’s been some active movement in the relevant WebKit bug since early December. Perhaps Safari 16 will include it? 🤞

How to prevent scrolling the page on iOS Safari 15 →


This content originally appeared on Bram.us and was authored by Bramus!


Print Share Comment Cite Upload Translate Updates
APA

Bramus! | Sciencx (2021-12-16T23:46:05+00:00) How to prevent scrolling the page on iOS Safari 15. Retrieved from https://www.scien.cx/2021/12/16/how-to-prevent-scrolling-the-page-on-ios-safari-15/

MLA
" » How to prevent scrolling the page on iOS Safari 15." Bramus! | Sciencx - Thursday December 16, 2021, https://www.scien.cx/2021/12/16/how-to-prevent-scrolling-the-page-on-ios-safari-15/
HARVARD
Bramus! | Sciencx Thursday December 16, 2021 » How to prevent scrolling the page on iOS Safari 15., viewed ,<https://www.scien.cx/2021/12/16/how-to-prevent-scrolling-the-page-on-ios-safari-15/>
VANCOUVER
Bramus! | Sciencx - » How to prevent scrolling the page on iOS Safari 15. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/16/how-to-prevent-scrolling-the-page-on-ios-safari-15/
CHICAGO
" » How to prevent scrolling the page on iOS Safari 15." Bramus! | Sciencx - Accessed . https://www.scien.cx/2021/12/16/how-to-prevent-scrolling-the-page-on-ios-safari-15/
IEEE
" » How to prevent scrolling the page on iOS Safari 15." Bramus! | Sciencx [Online]. Available: https://www.scien.cx/2021/12/16/how-to-prevent-scrolling-the-page-on-ios-safari-15/. [Accessed: ]
rf:citation
» How to prevent scrolling the page on iOS Safari 15 | Bramus! | Sciencx | https://www.scien.cx/2021/12/16/how-to-prevent-scrolling-the-page-on-ios-safari-15/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.