zoom event

by Deepak Kumar

JavaScript

(function(root, ns, factory) {
    "use strict";
    "undefined" != typeof module && module.exports ? module.exports = factory(ns, root) : "function" == typeof define && define.amd ? define("detect-zoom", function() {
        return factory(ns, root)
    }) : root[ns] = factory(ns, root)
})(window, "detectZoom", function() {
    var devicePixelRatio = function() {
        return window.devicePixelRatio || 1
    }, fallback = function() {
        return {
            zoom: 1,
            devicePxPerCssPx: 1
        }
    }, ie8 = function() {
        var zoom = Math.round(100 * (screen.deviceXDPI / screen.logicalXDPI)) / 100;
        return {
            zoom: zoom,
            devicePxPerCssPx: zoom * devicePixelRatio()
        }
    }, ie10 = function() {
        var zoom = Math.round(100 * (document.documentElement.offsetHeight / window.innerHeight)) / 100;
        return {
            zoom: zoom,
            devicePxPerCssPx: zoom * devicePixelRatio()
        }
    }, webkitMobile = function() {
        var deviceWidth = 90 == Math.abs(window.orientation) ? screen.height : screen.width,
            zoom = deviceWidth / window.innerWidth;
        return {
            zoom: zoom,
            devicePxPerCssPx: zoom * devicePixelRatio()
        }
    }, webkit = function() {
        var important = function(str) {
            return str.replace(/;/g, " !important;")
        }, div = document.createElement("div");
        div.innerHTML = "1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0", div.setAttribute("style", important("font: 100px/1em sans-serif; -webkit-text-size-adjust: none; text-size-adjust: none; height: auto; width: 1em; padding: 0; overflow: visible;"));
        var container = document.createElement("div");
        container.setAttribute("style", important("width:0; height:0; overflow:hidden; visibility:hidden; position: absolute;")), container.appendChild(div), document.body.appendChild(container);
        var zoom = 1e3 / div.clientHeight;
       ...