天天看点

浏览器中禁止滚动事件

代码如下:

/**
 * lu封装
 */
(function () {
    if (!window.lu) {
        window.lu = {};
    };

    window.lu = {
        mo: function (e) {
            e.preventDefault();
            e.stopPropagation();
        },
        /** 页面禁止滑动 */
        stop: function () {
            // document.body.style.overflow = 'hidden';
            $('body').css({
                'position': 'fixed',
                'height':'100%',
                'width': '100%',
                'overflow': 'hidden'
            });
            document.addEventListener("touchmove", this.mo, false); //禁止页面滑动
        },
        /***取消滑动限制***/
        move: function () {
            // document.body.style.overflow = ''; //出现滚动条
            $("body").css({
                'position': 'initial',
                'height': '100%',
                'width': '100%',
                'overflow':''
            });
            document.removeEventListener("touchmove", this.mo, false);
        }

    };
})();
           

该方法在百度浏览器和

继续阅读