Catching Mac trackpad zoom

后端 未结 5 539
感动是毒
感动是毒 2020-12-24 03:32

Currently in my application i am catching the mouse wheel events and perform zoom in or out on a Canvas element. If user uses Mac and tries to perform zoom with the trackpad

5条回答
  •  一生所求
    2020-12-24 04:16

    At least in Chrome, trackpad "pinch-to-zoom" triggers a wheel/mousewheel event that appears as though the ctrl key is pressed. You can capture this event just like any other wheel/mousewheel event and prevent its default from occurring. Here is an example using jQuery:

    $("canvas").on("mousewheel", function(e) {
        if (e.ctrlKey) {
            e.preventDefault();
            e.stopImmediatePropagation();
    
            // perform desired zoom action here
        }
    });
    

提交回复
热议问题