By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

Cross browser mouse wheel event handler

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.