Enable/Disable Scrolling in iPhone/iPad’s Safari
Today working on mobile theme for one portal I was needed to prevent scrolling of the screen when the popup window is opened.
After some googling I found the good and simple solution of this issue.
To prevent user from scrolling the screen you need to redefine touch move event
document.ontouchmove = function(e){ e.preventDefault(); }
Then if you need to enable screen scrolling you need to make a little tricky
document.ontouchmove = function(e){ return true; }
That works for me, and I like it.
Written by Andrey Krivko
Related protips
4 Responses
Wonderful! I've been trying with overflow:hidden; and it was causing page shift. This works like a charm.
I've found several attempts at this online but this method is the only one that worked well for me. Thank you very much for posting.
It's working fine but It's prevent the popup scroll. How to enable popup container scroll?
hello
good for me on android
but, when the body page is block from scrolling, i cannot scroll my div or modal
How to enable my div only in javascript?
Thank you