简体   繁体   中英

iPhone Browser: Disable page scroll while dragging html input field

I have made a HTML page. This page is smaller than Iphone screen. Let's say this is login page. The page contains text input fields.

I disabled scrolling the page this way:

document.ontouchmove = function(e){
    e.preventDefault();
}

That code prevents scrolling, but when I tap an input field and drag, than the page is scrolling anyway.

Is there a way to completely disable page scrolling in HTML at iPhone?

It worked for me

 $("body").bind("touchmove", function(e) { e.preventDefault(); });

The user can always scroll to the top by touching the status bar, so the best way to prevent scrolling is to keep scrolling. Put window.scrollTo(x, y) in a setInterval , and whenever the user scroll the page you can scroll it back to the right position.

When the user click on an input field, Mobile Safari might scroll up a bit to avoid keyboard covering the input field. Make sure that you scrolling behavior won't get the input field covered by the keyboard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM