Mousewheel & dommousescroll event in IE & Edge

前端 未结 3 576
春和景丽
春和景丽 2020-12-10 12:09

I have this code:





Title

&         


        
3条回答
  •  清歌不尽
    2020-12-10 12:22

    Edit

    After some research it seems that the problem is actually Microsoft's.

    There is an open issue about it in EdgeHTML issue tracker for almost one year already.

    Basically it says that wheel events do not work in Edge (And older IE versions) when using Precision Touchpads.

    By the way I dont delete the rest of the answer as it is still relevant. You should use wheel instead anyway.


    You should listen to wheel:

    window.addEventListener('wheel', mouseWheelEvent);
    

    It has replaced both mousewheel and DOMMouseScroll which are deprecated by now and is supported by all browsers.


    Cross browser example:

    window.addEventListener('wheel', mouseWheelEvent);   
    
    function mouseWheelEvent() {
        console.log("Fired");
    }

    Hodor!

    Hodor!

    Hodor!

    Hodor!

    Hodor!

    Hodor!

    Hodor!


    And JSFiddle demo

提交回复
热议问题