0

Mousewheel event is not triggering in Firefox, am using the jquery.mousewheel plugin, but even without it it was working fine in all browsers except Firefox. Here is my code:

    $('body').on('mousewheel', function(e){
            console.log(123);
            //some code...
   });   

Live example here

Any suggestions? Many thanks for all answers...

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
hjuster
  • 3,985
  • 9
  • 34
  • 51
  • Could you simply bind to `scroll` instead? Support [appears to be better](http://www.quirksmode.org/dom/events/scroll.html), although it fires in more situations. Additionally, the [`wheel`](https://developer.mozilla.org/en-US/docs/Web/Reference/Events/wheel) event has deprecated `mousewheel` in Firefox. Could the mousewheel plugin not be loading correctly? – rockerest Apr 06 '14 at 20:13
  • I can't use that in this situation, as there is no scrolling on that page... The mousewheel should just change the page on that example... – hjuster Apr 06 '14 at 20:16
  • Possibly already answered [here on SO](http://stackoverflow.com/q/16788995/2032064) – Mifeet Apr 06 '14 at 20:17
  • I've already seen that, but it didn't helped... – hjuster Apr 06 '14 at 20:18
  • Could you post un-minified, unbuilt source? I'm looking through your `main-built.js` and it looks really weird, not to mention your website never loads a jQuery module OR the mousewheel plugin module. – rockerest Apr 06 '14 at 20:25
  • Yeah, sorry I was trying that on localhost. Will upload now this version but not minified. – hjuster Apr 06 '14 at 20:27
  • Here is the home view: http://wheniamplaying.com/mspa/js/views/home.js Last part of the render method is causing the issue... – hjuster Apr 06 '14 at 20:32

2 Answers2

0

jquery.mousewheel is not loading properly.

You can verify this by going to your website, opening the developer console, and typing
$.fn.mousewheel or $.fn.unmousewheel and hitting CTRL+Enter.

Both return undefined.

It's possible this may work if you capture your mousewheel dependency as a parameter to your anonymous module, but if I'm being totally honest, every time I have to deal with jQuery plugins and requireJS, I just give up on the scoped modules and let jQuery do it's nasty thing in the global scope (which is why I use jQuery less and less these days).

As for why it worked in other browsers, I believe Webkit is the only engine to have added support for mousewheel. Because the jquery.mousewheel plugin is not loading, other browsers are deferring to their native implementations.

rockerest
  • 10,412
  • 3
  • 37
  • 67
  • Thats not the latest version online with the jquery.mousewheel plugin included, thats why its returning undefined... Sorry for confusion, I shouldn't post that link at all... I wanted to upload the latest version, but then I realised that I had to upload the new backend and new database, because there are loads of differences between that version and the latest one which i have on local... – hjuster Apr 06 '14 at 20:45
0

In older FF versions, you can bind mousewheel-event using pure JavaScript and DOMMouseScroll:

document.body.addEventListener("DOMMouseScroll", function(){ console.log(123); }, false);

Note, that DOMMouseScroll-event is deprecated. In newer Version, use wheel-event instead:

document.body.addEventListener("wheel", function(){ console.log(123); }, false);
Simon
  • 4,157
  • 2
  • 46
  • 87