1.可以給document的touchmove事件禁止掉就行了
|
1
2
3
|
document.querySelector(
'body'
).addEventListener(
'touchmove'
,
function
(e) {
e.preventDefault();
})
|
2.如果頁面有部分區域必須需要滑動,需要用touchmove事件的話,那么可以把那部分的touchmove事件過濾掉
比如我想要以下代碼中的bottom類可以用touchmove事件
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>微信禁止下拉露黑底</title>
</head>
<body>
<div class="top"></div>
<div class="bottom"></div>
</body>
</html>
用以下代碼就可以實現
document.querySelector('body').addEventListener('touchmove', function(e) {
if (!document.querySelector('.bottom').contains(e.target)) {
e.preventDefault();
}
})

