admin管理员组

文章数量:1302267

Below code is working fine on chrome however it doesn't work on Mozilla for some reason that I am not aware yet. Am i missing something ?

$(window).bind('mousewheel', function(event) {
    if (event.originalEvent.wheelDelta >= 0) {
        $('#currentMove').html('Movement: Scroll up');
        $('#currentMove').css('background','#98FB98');
        scrollUp++;
        $('#scrollUp').html(scrollUp);

    }
    else {
        $('#currentMove').html('Movement: Scroll down');
        $('#currentMove').css('background','#FFB6C1');
        scrollDown++;
        $('#scrollDown').html(scrollDown);
    }
});

Here is my fiddle: / Appreciate your help with this.

Below code is working fine on chrome however it doesn't work on Mozilla for some reason that I am not aware yet. Am i missing something ?

$(window).bind('mousewheel', function(event) {
    if (event.originalEvent.wheelDelta >= 0) {
        $('#currentMove').html('Movement: Scroll up');
        $('#currentMove').css('background','#98FB98');
        scrollUp++;
        $('#scrollUp').html(scrollUp);

    }
    else {
        $('#currentMove').html('Movement: Scroll down');
        $('#currentMove').css('background','#FFB6C1');
        scrollDown++;
        $('#scrollDown').html(scrollDown);
    }
});

Here is my fiddle: https://jsfiddle/w0wffbxc/ Appreciate your help with this.

Share asked Nov 29, 2017 at 9:09 shifushifu 6708 silver badges38 bronze badges 2
  • Possible duplicate of stackoverflow./questions/16788995/… – moon Commented Nov 29, 2017 at 9:15
  • 1 Possible duplicate of mousewheel event is not triggering in firefox browser – moon Commented Nov 29, 2017 at 9:16
Add a ment  | 

2 Answers 2

Reset to default 7

Here's your sqlfiddle fixed.

You should use wheel as mousewheel is not recognized by Firefox since version 3. Also with wheel, you should use event.originalEvent.deltaY instead.

Use wheel event instead. Its more of a standard now. This page also provides polyfills for old browsers https://developer.mozilla/en-US/docs/Web/Events/wheel

Ex

$(window).on('wheel', function(event){

    // deltaY obviously records vertical scroll, deltaX and deltaZ exist too
    if(event.originalEvent.deltaY < 0){
        // wheeled up
        console.log("Works Up");
    }
    else {
        // wheeled down
        console.log("Works Down");
    }
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>

本文标签: javascriptmousewheel event not working on firefoxStack Overflow