Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catching Mac trackpad zoom

Tags:

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?

like image 592
Erik Sapir Avatar asked Mar 14 '13 18:03

Erik Sapir


People also ask

How do I zoom in and zoom out on Mac 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.

How do I zoom in on my Mac trackpad?

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.

How do you zoom in on a trackpad?

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.


1 Answers

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     } }); 
like image 72
alexyaseen Avatar answered Sep 28 '22 09:09

alexyaseen