安卓手机微信浏览器禁止下拉时回弹出网址来源等信息

如果想禁止掉微信浏览器默认的下拉时回弹的效果,可以给body元素的touchmove事件禁止掉,如:

document.querySelector('body').addEventListener('touchmove', function(e) {
    e.preventDefault();
})

但是这样会禁掉所有的滚动效果,需求可能会是局部滚动,这时候可以把部分的touchmove事件过滤掉,比如我想让下面的列表用touchmove事件




    
    微信禁止下拉露黑底


    

用以下代码就可以实现

document.querySelector('body').addEventListener('touchmove', function(e) {
    if (!document.querySelector('.list').contains(e.target)) {
        e.preventDefault();
    }
})

你可能感兴趣的:(微信浏览器)