禁止微信网页下拉显示网页由某某提供【iPhone上拉失效,没有iPhone 无法具体测试原因】
简单理解就是:判断手指触摸移动走向-如果到顶之后-还在继续下拉,就阻止默认的 touchmove 事件【有用、无用请留言,谢谢】
建议写在 html 页面中,第一时间生效。
<script>
// 禁用微信下拉
let lastTouchY = 0;
window.addEventListener("touchend", () => {
lastTouchY = 0;
});
window.addEventListener(
"touchmove",
(e) => {
// 一根手指
if (e.touches.length === 1) {
// 到顶之后 && 继续下拉
if (
window.scrollY <= 0 &&
lastTouchY < e.touches[0].screenY
) {
try {
e.preventDefault();
} catch {}
}
lastTouchY = e.touches[0].screenY;
}
},
{
passive: false,
}
);
</script>
浙公网安备 33010602011771号