javascript-Android浏览器:获取比例因子

javascript-Android浏览器:获取比例因子,第1张

概述是否有可能以某种方式在Android浏览器上的javascript中获取当前的缩放比例?解决方法:TheAndroidBrowserandWebViewsupportaDOMpropertythatallowsyoutoquerythedensityofthecurrentdevice—thewindow.devicePixelRatioDOMproperty.Thevalueofthisprope

是否有可能以某种方式在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-Android浏览器:获取比例因子全部内容,希望文章能够帮你解决javascript-Android浏览器:获取比例因子所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1068989.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存