JavaScript - Zoom


How can we detect user zooming?

var zoom = document.documentElement.clientWidth / window.innerWidth;
ratio = document.width / window.innerWidth

How can we determine the current zoom level?

Reading out the zoom level directly is not possible, but you can get it by dividing screen.width by window.innerWidth if both properties are supported. Fortunately the zoom level is not important. What we need to know is how many CSS pixels currently fit on the screen, and we can get that information from window.innerWidth if it is supported.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License