在一个网络应用程序上工作,我想防止屏幕四处移动,所以我从这个开始:
$(document).on("touchmove", false);
...然后我意识到我div
需要能够滚动,所以我添加了:
$(document).on('touchmove', function(e) {
if (!$(e.target).parents().hasClass( 'touch-moveable' )) {
e.preventDefault();
}
});
工作正常,但现在在该 div 内的移动设备上滚动可能会导致整个屏幕再次移动。不是世界末日,但是……难道没有办法让一切都保持静止,只让一个 div 移动吗?
编辑
好的,虽然我敢打赌它可以合并并变得更优雅?:
$(document).on('touchmove', function(e) {
if (!$(e.target).parents().hasClass( 'touch-moveable' )) {
e.preventDefault();
}
});
$('.touch-moveable').on('touchmove',function(e){
e.stopPropagation();
});