In iOS 13.4+ you can now preventDefault
on "touchstart"
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…