Norbs Knight
Norbs Knight

Reputation: 169

Detect Android pinch to zoom using JavaScript (besides Hammer.js)

In IOS I use the $(window).resize() event to detect a pinch to zoom action. I tried this in an Android device but it doesn't trigger.

I'm trying to determine if the user pinched to zoom by comparing the "document.documentElement.clientWidth" and "window.innerWidth"

Any ideas on what event to use if there is a change in the window size?

Thanks and regards

Upvotes: 0

Views: 1810

Answers (1)

Ohgodwhy
Ohgodwhy

Reputation: 50787

You need to bind to the gesturechange event. This will allow you to detect the scaling ratio, and resize accordinly.

$(window).on('gesturechange', function(e){ 
     console.log(e) 
});. 

The e wil contain all the information you need to know about the event, including the original scale size, and the current scale size, so you can resize and react accordingly.

Upvotes: 1

Related Questions