gpt4 book ai didi

javascript - 防止在 iPad Safari 中的网页之间滑动

转载 作者:太空狗 更新时间:2023-10-29 15:02:55 33 4
gpt4 key购买 nike

从我 iPad 的 Safari 浏览器的左右边缘滑动,在当前打开的网页之间移动。有什么办法可以预防吗?

我尝试在 stopPropagationpreventDefault 的页面边缘添加 touchstarttouchmove 处理程序,但它们似乎没有效果,touch-action CSS 也没有效果。

类似的问题在 2014 年被问及是否定的答复: iOS 7 - is there a way to disable the swipe back and forward functionality in Safari?

现在 2018 年有变通办法吗?

最佳答案

在 iOS 13.4+ 中,您现在可以 preventDefault"touchstart"

假设我们有一个 <div class="block-swipe-nav">在跨越整个视口(viewport)宽度的页面上,我们希望防止在该元素上滑动导航。

const element = document.querySelector('.block-swipe-nav');

element.addEventListener('touchstart', (e) => {

// is not near edge of view, exit
if (e.pageX > 10 && e.pageX < window.innerWidth - 10) return;

// prevent swipe to navigate gesture
e.preventDefault();
});

我写了a short article on blocking swipe以及一些额外的信息。

关于javascript - 防止在 iPad Safari 中的网页之间滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50156425/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com