简体   繁体   English

如何在iPad webapp上禁用滚动?

[英]How do I disable scrolling on an iPad webapp?

The usual: 通常:

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

isn't working for me. 不适合我。 I am trying to make my iPad webapp feel as native as possible. 我想让我的iPad webapp感觉尽可能本地化。 Any answer is appreciated. 任何答案都表示赞赏。

Put that handler on the document element directly, not on the body . 将该处理程序直接放在document元素上,而不是放在body

I've had success with the following: 我在以下方面取得了成功:

<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">

Then with jQuery: 然后使用jQuery:

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

This will also be useful if you want to handle different orientations: 如果您想要处理不同的方向,这也很有用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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