0

I want to create function mousewheel in jQuery, when I want to check the delta the result is always "undefined". Please help me. Here is my code:

$(document).ready(function(){
$('#container').bind('mousewheel', function(event,delta){
     alert(delta)

});
})
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
sein
  • 159
  • 1
  • 2
  • 11

2 Answers2

0

What browser are you using to test in? There is more than one way to bind a mouse wheel event and depending on the browser will determine where to find the delta. In Firefox it's event.detail and it's values can be 1, 2, -1, -2, etc however in non-Firefox browsers you're looking at wheelDelta which appears to be what you coded for.

A good resource on mousewheel events is here which is what I used when I wrote my jQuery mousewheel plugin.

Brandon Buck
  • 7,177
  • 2
  • 30
  • 51
0

No need to write your own plugin. Use this script and you should be good to go!

<script type="text/javascript" src="https://raw.github.com/brandonaaron/jquery-mousewheel/master/jquery.mousewheel.js"></script>

DEMO: http://jsfiddle.net/dirtyd77/WmwfY/

Side Note: Just a suggestion, you may want to use console.log() rather than alert() in the future.

Community
  • 1
  • 1
Dom
  • 38,906
  • 12
  • 52
  • 81