本文介绍了有没有一种方法可以在iOS的Safari中禁用向后滑动动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想完全禁用SPA上的向后滑动动画.这样一来,我就可以在SPA中使用一些滑动手势.目前,在iOS上,您在触发某些手势时往往还会触发向后滑动手势.
I would like to disable the swipe back animation totally on a SPA. That would allow me to use some swiping gestures within the SPA. At the moment on iOS you tend to also trigger the swipe back gesture when triggering certain gestures.
html, body {
overscroll-behavior-x: none;
}
if (window.safari) {
history.pushState(null, null, location.href);
window.onpopstate = function(event) {
history.go(1);
};
}
推荐答案
在iOS 13.4+中,您现在可以在"touchstart"
开始事件上 preventDefault()
停止导航操作.
假设我们在页面上有一个< div class ="block-swipe-nav">
,该页面跨越视口的整个宽度,并且我们希望避免在该元素上滑动浏览
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.
这篇关于有没有一种方法可以在iOS的Safari中禁用向后滑动动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!