A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

Detect Zoom Level

collimarco
2019-11-26

Currently there is no way to detect the zoom level with Javascript reliably.

That would be useful in many situations.

The current state is a complete mess;

simevidas
2019-11-30

Could you describe the main use-cases?

collimarco
2019-11-30

My specific use case is to avoid gesture detection (with touch events) when the page is zoomed-in, otherwise the user sometime accidentally triggers a swipe or other gestures. There are certainly many other use cases… The browser could simply make that value available to the app… why not? It should be very simple. Otherwise there are hundreds of workarounds that don’t work or work only on a single browser -.-

simevidas
2019-11-30

I think the Visual Viewport API can be used to detect when the page is zoomed. Please take a look.

collimarco
2019-11-30

Wow, thanks! window.visualViewport.scale seems exactly what I need. Tested on Chrome and Safari and it works. Unfortunately its browser support is still partial, but it is certainly the right solution for the future.