【发布时间】:2013-07-21 07:17:45
【问题描述】:
这与其说是一个问题,不如说是一个问题的解决方案。
很难找到解决方案,直到我偶然发现了由 hallodom (How to disable scrolling temporarily?) 添加的答案,该答案正在响应一个略有不同的问题。
我想明确记录问题的答案。其他解决方案是最受欢迎的,并将增加对话。
hallodom 的解决方案是:
对于移动设备,您需要处理touchmove 事件:
$('body').bind('touchmove', function(e){e.preventDefault()})
并取消绑定以重新启用滚动。在 iOS6 和 Android 2.3.3 中测试
$('body').unbind('touchmove')
我使用了 hallodom 的解决方案,只需将它们附加到单击 DOM 中的对象时调用的函数:
$('body').on('click', 'button', function(e){
if($(this).prop('checked')){
disable_scroll();
}else{
enable_scroll();
}
});
function disable_scroll() {
$('body').bind('touchmove', function(e){e.preventDefault()});
}
function enable_scroll() {
$('body').unbind('touchmove');
}
【问题讨论】:
-
我的回答对你有帮助吗?
标签: javascript jquery jquery-mobile mobile scroll