如何在iPad webapp上禁用滚动?

Val*_*lli 21 javascript scroll web-applications ipad

通常:

document.body.addEventListener('touchmove',function(event){event.preventDefault();},false); 
Run Code Online (Sandbox Code Playgroud)

不适合我.我想让我的iPad webapp感觉尽可能本地化.任何答案都表示赞赏.

Aln*_*tak 53

将该处理程序document直接放在元素上,而不是放在元素上body.

我在以下方面取得了成功:

<meta name="viewport" content="user-scalable=1.0,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
Run Code Online (Sandbox Code Playgroud)

然后使用jQuery:

$(document).bind('touchmove', false);
Run Code Online (Sandbox Code Playgroud)

如果您想要处理不同的方向,这也很有用:

<link rel="stylesheet" type="text/css" href="css/main.css" media="all">
<link rel="stylesheet" type="text/css" href="css/landscape.css" media="all and (orientation:landscape)">
<link rel="stylesheet" type="text/css" href="css/portrait.css" media="all and (orientation:portrait)">
Run Code Online (Sandbox Code Playgroud)