问题描述
我想知道是否有一种方法可以检测所有现代浏览器都支持的页面缩放级别.我已经尝试过了: how-to-detect-page-zoom-level-在所有现代浏览器中
I was wondering if there's a way to detect the page zoom level which is supported by all modern browsers. I've already tried this:how-to-detect-page-zoom-level-in-all-modern-browsers
但不幸的是,它与我尝试过的所有浏览器都不完全兼容.
but unfortunately it is not fully compatible with all the browser I tried.
是否有更通用的方法或jquery库来实现?
Is there a more general method, or a jquery library to achieve that?
推荐答案
这取决于您的目标.如果仅需要当前缩放比例,则可以使用:
It depends on what your goal. If you only need the current scaling you can use:
window.devicePixelRatio
但是该值不等于所有设备上的缩放级别,因为在HighDPI设备(4k显示器,智能手机等)上,起始值不为1,因为存在默认缩放来补偿更高的像素分辨率.
But the value is not equal to the zoom level on all devices because on HighDPI devices (4k Display, Smartphone, …) the start value is not 1 because there is a default zoom to compensate the higher pixel resolution.
这篇关于在所有现代浏览器上检测缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!