阻止iOS 11设备中的Safari页面触摸/滚动

时间:2018-05-23 20:29:37

标签: javascript html ios

我以前使用以下代码来阻止网页在触摸设备上滚动(特别是在iOS上测试)。

disableScroll = false;
$(document).on('touchmove',function(e) {
    if (disableScroll) {
        e.preventDefault();
    }
});

然而,自iOS 11以来,这已不再适用。使用iOS模拟器我可以回去测试iOS 9和iOS 10,它可以正常工作,但不再适用于iOS11。有人可以建议替代解决方案吗?

例如,在iOS 9/10上测试此类似功能有效,但在iOS 11上无效。https://benfrain.com/preventing-body-scroll-for-modals-in-ios/

1 个答案:

答案 0 :(得分:1)

类似的问题,但使用普通的javascript,请在​​https://stackoverflow.com/a/49582193

回答。
document.addEventListener('touchmove', function(e) {
    e.preventDefault();
}, { passive: false });