更新时间:2022-01-15 07:35:00
在 iOS 13.4+ 中,您现在可以在 "touchstart"
启动事件上 preventDefault()
停止导航操作.
In iOS 13.4+ you can now preventDefault()
on the "touchstart"
start event to stop the navigation action.
假设我们在页面上有一个 <div class="block-swipe-nav">
跨越视口的整个宽度,我们想防止在该元素上滑动导航.
Let's say we have a <div class="block-swipe-nav">
on the page that spans the entire width of the viewport and we want to prevent swipe navigation on that element.
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();
});
我写了一篇关于阻止滑动的简短文章 一些额外的信息.
I've written a short article on blocking swipe with some additional information.