Toza
Toza

Reputation: 1358

Onmousewheel event and Mozilla Firefox

I'm trying to make an element change it's opacity depending on the direction the way the scrollwheel is being scrolled (if scrollwheel is going "up" opacity goes to 1.0, otherwise 0.3), so I attached an event onmousewheel="change(event);" to the html body and did the following in JS:

function transp(e){
    var element = document.getElementById("elem");

    if(e.wheelDelta >= 120){
        element.classList.remove('scroll-minus');
        element.classList.add('scroll-plus');
    }
    else if(e.wheelDelta <= -120){
        element.classList.add('scroll-minus');
        element.classList.remove('scroll-plus');
    }
}

I won't bother posting CSS3 info, it's just CSS3 stuff like opacity: 0.2/1.0, transition: 2s... CSS isn't a problem

This works perfectly on google chrome and IE, but firefox doesn't seam to listen to the onmousewheel event. Is there any other similar event that it might listen to? How is it used?

Upvotes: 1

Views: 105

Answers (1)

poke
poke

Reputation: 388463

The mousewheel event is non-standard, and not supported in Firefox. You can use the wheel event instead which is standardized albeit not completely supported yet. So if you want a cross-browser solution, you will probably have to mix these events, or make use of the scroll event instead.

Upvotes: 2

Related Questions