JQuery - Can I query the MacBook Pro Trackpad?

后端 未结 5 1532
梦毁少年i
梦毁少年i 2020-12-17 03:48

Can I use JQuery to query the Trackpad? So I can do something like this:

Pseudo Javascript (JQuery)

$(document).keyInput().trackpadTwoFingersLeft(fun         


        
5条回答
  •  忘掉有多难
    2020-12-17 04:35

    There is a wheel event which you can use to detect two-finger swipe on Mac.

    Your code could look something like this:

          $('element').on('wheel', function(e){
            var eo = e.originalEvent;
            if(Math.abs(eo.wheelDeltaY) < 10 && Math.abs(eo.wheelDeltaX) > 2){
              e.preventDefault();
    
              if(eo.wheelDeltaX < -100 && !scope.item.swipedLeft){
                  // swipe left
              }
    
              if(eo.wheelDeltaX > 100 && scope.item.swipedLeft){
                  // swipe right
              }
            }
          });
    

    This could possibly not work in some older browser and/or Mozilla (as it fires some different event for the wheel movement), but as long as you implement this as an additional/helper feature, this code should suffice.

提交回复
热议问题