2011-10-11 138 views
21

通常:如何禁用iPad webapp上的滾動?

document.body.addEventListener('touchmove',function(event){event.preventDefault();},false); 

是不是爲我工作。我試圖讓我的iPad webapp儘可能地感受到原生。 任何答案表示讚賞。

+0

可能的副本[禁用iPhone Web應用程序中的滾動?](http://stackoverflow.com/questions/2890361/disable-scrolling -in-an-iphone-web-application) – Gajus

回答

52

將該處理程序直接放在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"> 

然後用jQuery:

$(document).bind('touchmove', false); 

這也將是,如果你要處理不同的方向有用:

<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)"> 
+0

非常感謝你的工作完美 – Valli

+0

只是好奇,你能不能把處理程序放在'window'對象上? – skeggse