码迷,mamicode.com
首页 > Web开发 > 详细

JS禁用和启用鼠标滚轮滚动事件

时间:2015-06-10 11:51:07      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:

// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
var keys = [37, 38, 39, 40];

function preventDefault(e) {
  e = e || window.event;
  if (e.preventDefault)
      e.preventDefault();
  e.returnValue = false;  
}

function keydown(e) {
    for (var i = keys.length; i--;) {
        if (e.keyCode === keys[i]) {
            preventDefault(e);
            return;
        }
    }
}

function wheel(e) {
  preventDefault(e);
}

function disable_scroll() {
  if (window.addEventListener) {
      window.addEventListener(‘DOMMouseScroll‘, wheel, false);
  }
  window.onmousewheel = document.onmousewheel = wheel;
  document.onkeydown = keydown;
}

function enable_scroll() {
    if (window.removeEventListener) {
        window.removeEventListener(‘DOMMouseScroll‘, wheel, false);
    }
    window.onmousewheel = document.onmousewheel = document.onkeydown = null;  
}

  

JS禁用和启用鼠标滚轮滚动事件

标签:

原文地址:http://www.cnblogs.com/yangwenbin/p/4565541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!