How to detect page zoom level in all modern browsers?

后端 未结 28 1774
慢半拍i
慢半拍i 2020-11-21 05:27
  1. How can I detect the page zoom level in all modern browsers? While this thread tells how to do it in IE7 and IE8, I can\'t find a good cross-browser solution.

28条回答
  •  后悔当初
    2020-11-21 06:03

    Basically, we have:

    • window.devicePixelRatio which takes into account both browser-level zoom* as well as system zoom/pixel density.
      * — on Mac/Safari zoom level is not taken into account
    • media queries
    • vw/vh CSS units
    • resize event, which is triggered upon zoom level change, cause effective size of the window changes

    that should be enough for normal UX. If you need to detect zoom level that might be a sign of bad UI design.

    Pitch-zoom is harder to track and is not considered currently.

提交回复
热议问题