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, there is no event and what actually happens is zoom in/out of browser.
Is there a way to catch the zoom event performed with the trackpad?
If you're using a laptop with a trackpad, you have another great single window zooming option right at your fingertips. Simply place two fingers on your trackpad and pinch them together to zoom out or move them apart to zoom in.
You can use the trackpad on your Mac or an Apple wireless mouse to zoom in on part of the screen. On your Mac, choose Apple menu > System Preferences, click Accessibility , then click Zoom. Select “Use scroll gesture with modifier keys to zoom” to turn on zooming.
Scroll: Place two fingers on the touchpad and slide horizontally or vertically. Zoom in or out: Place two fingers on the touchpad and pinch in or stretch out.
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 } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With