开发者

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

开发者 https://www.devze.com 2023-03-17 04:16 出处:网络
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:

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 开发者_如何学Pythoncaptured 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消