Bel*_*via 4 scrollbar draggable jquery-mobile cordova
我目前正在使用phonegap 1.5和jQuery Mobile开发iOS应用程序.
我了解我们可以使用以下javascript禁用页面拖动:
function preventBehavior(e)
{
e.preventDefault();
};
document.addEventListener("touchmove", preventBehavior, false);
Run Code Online (Sandbox Code Playgroud)
但是,如果启用了上述内容滚动,则无法进行内容滚动.
有什么办法可以阻止用户拖动页面但是允许滚动吗?
我尝试过使用iScroll.为此,我需要手动做一个
scrollbar.refresh();
Run Code Online (Sandbox Code Playgroud)
在每页的pageinit事件下.不幸的是,我确实有很多需要滚动的页面.=(
有没有其他方法可以使用它来启用滚动而不使用第三方插件?
将其添加到HTML头
<script type="text/javascript">
touchMove = function(event) {
event.preventDefault();
}
</script>
Run Code Online (Sandbox Code Playgroud)
然后设定
ontouchmove="touchMove(event)"
Run Code Online (Sandbox Code Playgroud)
在您要禁用拖动的每个页面的最外层div中.例:
<div id="mypage" ontouchmove="touchMove(event)">
Run Code Online (Sandbox Code Playgroud)
对于没有ontouchmove ="touchMove(event)"的页面,可以进行拖动.
此解决方案要求您不要为函数 preventBehavior ()包含phonegap模板代码.删除或评论出来:
//function preventBehavior(e)
//{
// e.preventDefault();
//};
//document.addEventListener("touchmove", preventBehavior, false);
Run Code Online (Sandbox Code Playgroud)
更详细的信息:http://phonegap.pbworks.com/w/page/16494815/Preventing-Scrolling-on-iPhone-Phonegap-Applications
| 归档时间: |
|
| 查看次数: |
12946 次 |
| 最近记录: |