如何在android 2.2浏览器上使用javascript检测缩放级别

时间:2013-01-15 14:07:18

标签: javascript android zoom

我已经看到了如何检测桌面浏览器缩放级别的多个示例,但我似乎无法找到如何为Android 2.2浏览器执行此操作。

此示例适用于桌面中的chrome:

   function detectZoom() {
    var screenCssPixelRatio = (window.outerWidth - 8) / window.innerWidth;
    zoomLevel = 0;

    if (screenCssPixelRatio >= .46 && screenCssPixelRatio <= .54) {
      zoomLevel = "-4";
    } else if (screenCssPixelRatio <= .64) {
      zoomLevel = "-3";
    } else if (screenCssPixelRatio <= .76) {
      zoomLevel = "-2";
    } else if (screenCssPixelRatio <= .92) {
      zoomLevel = "-1";
    } else if (screenCssPixelRatio <= 1.10) {
      zoomLevel = "0";
    } else if (screenCssPixelRatio <= 1.32) {
      zoomLevel = "1";
    } else if (screenCssPixelRatio <= 1.58) {
      zoomLevel = "2";
    } else if (screenCssPixelRatio <= 1.90) {
      zoomLevel = "3";
    } else if (screenCssPixelRatio <= 2.28) {
      zoomLevel = "4";
    } else if (screenCssPixelRatio <= 2.70) {
      zoomLevel = "5";
    } else {
      zoomLevel = "0";
    }

    return zoomLevel;
}

任何帮助表示感谢。

0 个答案:

没有答案