/**
* 禁止滑动贯穿,passive需要设置为false,表示组织浏览器的默认行为
*/
const forbidTouchScroll = {
bind: (idName, handlerFn) => {
document.getElementById(idName).addEventListener("touchmove", handlerFn, { passive: false })
},
unbind: (idName, handlerFn) => {
document.getElementById(idName).removeEventListener("touchmove", handlerFn, { passive: false })
},
handler: (e) => {
e.preventDefault()
}
}
//调用
forbidTouchScroll("mask",forbidTouchScroll.handler)
一个对象解决滚动贯穿问题
最新推荐文章于 2024-09-14 18:52:56 发布