>  Q&A  >  본문

javascript - 如何在手机上禁止浏览器的网页滚动

怎么写javascript和html才能禁止网页的上下,左右滚动啊,是在手机浏览器上,onmousewheel=“return false”在PC上有用,但在手机上没用,,用jquery mobile写可以吗?。。急求~~来个实际操作过的大神啊~~

PHP中文网PHP中文网2749일 전1484

모든 응답(13)나는 대답할 것이다

  • 大家讲道理

    大家讲道理2017-04-10 13:12:11

    阻止默认
    $("body").on("touchmove",function(event){
    event.preventDefault;
    }, false)
    
    然后点击取消或者确定时再取消body上的绑定
    $("body").off("touchmove");

    회신하다
    0
  • 巴扎黑

    巴扎黑2017-04-10 13:12:11

    这样也不行啊!页面还是会被拖拽

    document.addEventListener('touchmove', function (e) {
        if (e.target.nodeName == '#document') {
            e.preventDefault();
        } else {
            e.stopPropagation();
        }
    })

    회신하다
    0
  • ringa_lee

    ringa_lee2017-04-10 13:12:11

    document.ontouchstart = function(){
                            return false;   // true 允许滚动  
                        };

    회신하다
    0
  • 취소회신하다