如何取消微信web页面顶部下拉后出现黑色的底部?

如题:

clipboard.png
如何禁止如图中出现的内容?有没有知道的大神

阅读 3.2k
2 个回答

1.可以给document的touchmove事件禁止掉就行了

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

无法禁止,就像android chrome浏览器无法禁止页面整体下拉刷新

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题