Check if user is scrolling with trackpad?

后端 未结 5 1101
鱼传尺愫
鱼传尺愫 2020-12-08 23:16

I have created a site where users are able to scroll through a gallery using mouse scroll or arrow up/down. It is working like I want it to, and changing one image pr scroll

5条回答
  •  盖世英雄少女心
    2020-12-08 23:55

    I found out that the magic number here was 40.

    It seems that with the trackpad (probably with the magic mouse too) the delta get increased 40 times.

    And it stays that way even if you take back your normal mouse and scroll with it later.

    So what I did, using the jquery mousewheel plugin :

    b.mousewheel(function(evt,delta,deltaX,deltaY){
        if(Math.abs(deltaY)>=40)
            deltaY/=40;
        if(Math.abs(deltaX)>=40)
            deltaX/=40;
    
        //Do your stuff here.
    });
    

提交回复
热议问题