kiinlam
11/3/2015 - 3:23 AM

onMouseWheel, do something

onMouseWheel, do something

  function bindMouseWheel(callback) {
    var body = document.body;
    var holding = false;
    if ('onmousewheel' in body) {
      body.onmousewheel = function (e) {
        if (holding) return false;
        holding = true;
        var event = e || window.event;
        if (event.wheelDelta < 0) {
          callback('down');
        } else {
          callback('up');
        }
        setTimeout(function () {
          holding = false;
        }, 100);
      }
    } else {
      body.addEventListener("DOMMouseScroll", function(e) {
        if (holding) return false;
        holding = true;
        if (e.detail > 0) {
          callback('down');
        } else {
          callback('up');
        }
        setTimeout(function () {
          holding = false;
        }, 100);
      });
    }
  }