代码改变世界

mousewheel

2016-06-30 15:10  改吧  阅读(311)  评论(0编辑  收藏  举报

判断鼠标往上还是往下滚动

html代码:

<div class="div">

</div>

css代码:

.div{
  position:absolute;

  width:100%;

  height:120%;

  border:1px red solid;

}

js代码:

/IE CHORME/

document.body.onmousewheel=function(event){

  event=event||window.event;

  var direction=event.wheelDelta&&(event.wheelDelta>0?"mouseup":"mousedown");

  console.log(direction);

}

 

/firefix/

document.body.addListener('DOMMouseScroll',function(event){

  var direction=event.detail&&(event.detail>0?"mousedown":"mouseup");

  console.log(direction);

}