1. 程式人生 > >微信h5頁面禁止下拉出現網頁來源等

微信h5頁面禁止下拉出現網頁來源等

技術分享 來源 分享 lsp highlight pan align alt ace

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();
    }
})

微信h5頁面禁止下拉出現網頁來源等