首页 > 技术文章 > 原生js禁止页面滚动

lanshengzhong 2017-12-06 10:08 原文

    // 开启、禁止页面滚动
    bodyScroll: {
       e(e) { e.preventDefault();
// 注意此处代码片段必须这样提出来已保证传入下边两个事件的处理程序一样才生效,分别写到事件处理程序中不生效。
     },
     // 开启滚动 
     open() {
       document.body.removeEventListener(
'touchmove', this.e, false);
     },
    
// 禁止滚动
  
close() {
       document.body.addEventListener(
'touchmove', this.e, false);
    }
  }

 

推荐阅读