469,582 Members | 2,477 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,582 developers. It's quick & easy.

Cross browser mouse wheel event handler

cjl
Hey all:

I'm trying to write a cross-browser (IE and firefox) event handler for
the mousewheel. Basically my web app is an image viewer, so if you
scroll "down" with the wheel the next image should be displayed and if
you scroll "up" the previous image should be displayed.

So far I have:

function handleMouseWheel(e)
{
if (!e) e = window.event;

if ( e.wheelDelta <= 0 || e.detail > 0) { changeImage(1); }
else { changeImage(-1); }
}

This code works in IE and in Firefox to the desired effect. The
problem I am having is with registering the event handler.

The following works for IE:
document.onmousewheel = handleMouseWheel;

And the following works for Firefox:
window.addEventListener("DOMMouseScroll", handleMouseWheel, false);

But when I add the firefox event handler to my code, IE chokes with an
error "Object doesn't support this property or method".

What do I need to do to "hide" the firefox event handler code from IE?

-CJL

Oct 8 '05 #1
1 3441
cjl
Hmmm:
What do I need to do to "hide" the firefox event handler code from IE?


Looks like all I need to do is:

if (window.addEventListener) {
window.addEventListener("DOMMouseScroll", handleMouseWheel, false); }
else { document.onmousewheel = handleMouseWheel; }

Is this correct? Anyway, works for me.

-CJL

Oct 8 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Steve Belanger | last post: by
6 posts views Thread by AccessWhiz | last post: by
1 post views Thread by DotNetMania | last post: by
2 posts views Thread by Anders Eriksson | last post: by
13 posts views Thread by Nathan | last post: by
4 posts views Thread by ML | last post: by
1 post views Thread by Alex Calder | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.