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

--------------------------------2017-01-09更新---------------------------------

1月6号得知消息:微信iOS客户端将于2017年3月1日前逐步升级为WKWebview内核

当更新为WKWebview后,可将position设置为fixed;其就不会上下滑动。

---------------------------------------END----------------------------------------

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

 

转载于:https://www.cnblogs.com/cococe/p/10475783.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值