开发者

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 dis开发者_JAVA技巧able page scrolling in HTML at iPhone?


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.


It worked for me

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜