Why does Firefox not pass all mouse wheel events to my javascript application?
Asked Answered
L

1

6

I'm using the protovis library (http://mbostock.github.com/protovis/) to draw a graph.
I uploaded the code I'm using in case someone wants to take a look at it:
http://jsfiddle.net/zobel/brEAD/

Here is my problem: Under Firefox, when I use the mouse wheel to zoom in or out, some mouse wheel events are not captured by my application but by Firefox itself. The result is that i end up getting a mix of zooms and page scrolls. You can test this by shrinking the Firefox window until the scroll bar gets visible.
This problem does not occur under Opera. Why does it happen and how can I solve it?
Thanks a lot in advance.

Lauzon answered 5/7, 2011 at 12:36 Comment(2)
please post a demo of the minimum program that demonstrates the problem at jsfiddle.net rather than a link to a zip of your whole sourceRunstadler
Thanks Alnitak, here is the jsfiddle jsfiddle.net/zobel/brEADLauzon
P
3

May be a bug (or simple omission) in the JavaScript library. The library needs to preventDefault() on the DOMMouseScroll event.

Thanks to event bubbling, you can do this yourself on any DOM object that's a parent node of the graph. Here's one simple example:

document.body.addEventListener('DOMMouseScroll', function(e){
    e.preventDefault();
}, false);

This won't work in older versions of IE, since it doesn't support addEventListener, but you get the point. I recommend using another general-purpose JavaScript library (like jQuery), and use that to set your event handler.

Peery answered 6/7, 2011 at 21:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.