移动端阻止body左右偏移

如果一直找不到你的CSS问题,就用下面的CSS解决吧

html,body{
    overflow-x: hidden;
  }

原生JS



function bodyScroll(){
    e.preventDefault();
}
document.addEventListener('touchmove', bodyScroll, false); //阻止
document.removeEventListener('touchmove', bodyScroll, false); //激活

或者

document.addEventListener('touchmove', function(event) {
    event.preventDefault();
}, false);

 

或者

function stopScroll(e){
    document.documentElement.style.overflow='hidden';
}

jQuery

$('body').on('touchmove',function(event){event.preventDefault();});
发布了65 篇原创文章 · 获赞 11 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/u011280778/article/details/100615426
今日推荐