移动端禁止页面拖动 h5禁止拖动页面

 

PC上css控制滚动仅css("overflow","hidden")已足够。

但是,如果在Mobile上还是可以拖动的!所以需要监听touchmove事件。

 

页面禁止拖动、滚动:

$("html,body").css("overflow","hidden").css("height","100%");
                        document.body.addEventListener('touchmove', self.welcomeShowedListener, false);

 

恢复页面拖动、滚动:

$("html,body").css("overflow","").css("height","");
                    document.body.removeEventListener('touchmove', detail.welcomeShowedListener, false);

 

参考:

在移动端设置overflow:hidden为什么页面还能滚?要怎么禁止

移动端的touch事件处理

addEventListener()与removeEventListener() 用法详解

 

posted @ 2016-07-07 14:10  程序员斯文  阅读(7750)  评论(0编辑  收藏  举报