[英]jQuery Mobile - Enable scrolling disable page dragging
I am currently developing an iOS app using phonegap 1.5 and jQuery Mobile. 我目前正在使用phonegap 1.5和jQuery Mobile开发iOS应用程序。
I understand that we can disable page dragging using the following javascript: 我了解我们可以使用以下javascript禁用页面拖动:
function preventBehavior(e)
{
e.preventDefault();
};
document.addEventListener("touchmove", preventBehavior, false);
However, content scrolling would not work if the above is enabled. 但是,如果启用了上述内容滚动,则无法进行内容滚动。
Is there any way I prevent users from dragging the page yet allow scrolling? 有什么办法可以阻止用户拖动页面但是允许滚动吗?
I have tried using iScroll. 我尝试过使用iScroll。 For that I would need to manually do a
为此,我需要手动做一个
scrollbar.refresh();
under the pageinit event on every page. 在每页的pageinit事件下。 Unfortunately, I do have many pages that require scrolling.
不幸的是,我确实有很多需要滚动的页面。 =(
=(
Are there any other methods which I can use to enable scrolling without using 3rd party plugins? 是否还有其他方法可以在不使用第三方插件的情况下启用滚动功能?
Add this to HTML head 将其添加到HTML头
<script type="text/javascript">
touchMove = function(event) {
event.preventDefault();
}
</script>
then set 然后设定
ontouchmove="touchMove(event)"
in the outermost div for every page that you want to disable dragging. 在您要禁用拖动的每个页面的最外层div中。 Example:
例:
<div id="mypage" ontouchmove="touchMove(event)">
Dragging will be possible for pages that don't have ontouchmove="touchMove(event)" . 对于没有ontouchmove =“touchMove(event)”的页面,可以进行拖动。
This solution requires that you do not include the phonegap templete code for function preventBehavior() . 此解决方案要求您不要为函数 preventBehavior ()包含phonegap模板代码。 Remove or comment it out:
删除或评论出来:
//function preventBehavior(e)
//{
// e.preventDefault();
//};
//document.addEventListener("touchmove", preventBehavior, false);
More detailed info here: http://phonegap.pbworks.com/w/page/16494815/Preventing-Scrolling-on-iPhone-Phonegap-Applications 更详细的信息: http : //phonegap.pbworks.com/w/page/16494815/Preventing-Scrolling-on-iPhone-Phonegap-Applications
$(document).delegate('.ui-page', 'touchmove', false);
这更有可能起作用,取决于您希望禁用触摸的内容。
I'm using jQuery Mobile and the following (executed on DOM ready) works for me: 我正在使用jQuery Mobile,以下(在DOM就绪上执行)对我有用:
$('body').on('touchmove', function(e) {
e.preventDefault();
});
Note that returning false or calling e.stopPropagation() will cause children of the body to not respond to the 'touchmove' event as well. 请注意,返回false或调用e.stopPropagation()将导致正文的子级也不响应“touchmove”事件。 Perhaps you are doing that in one of your event handlers which is stopping event bubbling.
也许你在一个阻止事件冒泡的事件处理程序中这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.