是否有可能以某种方式在 android 浏览器上的 javascript 中获取当前缩放因子?
最佳答案
The Android Browser and WebView support a DOM property that allows you to query the density of the current device—the window.devicePixelRatio DOM property. The value of this property specifies the scaling factor used for the current device. For example, if the value of window.devicePixelRatio is "1.0", then the device is considered a medium density device and no scaling is applied by default; if the value is "1.5", then the device is considered a high density device and the page is scaled 1.5x by default; if the value is "0.75", then the device is considered a low density device and the page is scaled 0.75x by default. Of course, the scaling that the Android Browser and WebView apply is based on the web page's target density—as described in the section about Defining the viewport target density, the default target is medium-density, but you can change the target to affect how your web page is scaled for different screen densities.
例如,您可以使用 JavaScript 查询设备密度:
if (window.devicePixelRatio == 1.5) {
alert("This is a high-density screen");
} else if (window.devicePixelRatio == 0.75) {
alert("This is a low-density screen");
}
有关更多信息,您可以查看 Tageting Screens from Web Apps
关于javascript - 安卓浏览器 : get scale factor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4448583/