微信h5页面禁止下拉出现网页来源等

时间:2017-05-25 17:17:08   收藏:0   阅读:748

 

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();
    }
})
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!