diff --git a/detect-zoom.js b/detect-zoom.js index bdb2a18..1afc1a7 100644 --- a/detect-zoom.js +++ b/detect-zoom.js @@ -32,6 +32,21 @@ return window.devicePixelRatio || 1; }; + /** + * Use svg:currentScale if supported by the browser + * @return {Number} + * @private + */ + var svgZoom = function(){ + var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); + svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); + svg.setAttribute('version', '1.1'); + document.body.appendChild(svg); + var zoom = svg.currentScale; + document.body.removeChild(svg); + return Math.round(zoom * 100) / 100; + } + /** * Fallback function to set default values * @return {Object} @@ -77,7 +92,7 @@ */ var chrome = function() { - var zoom = Math.round(((window.outerWidth) / window.innerWidth)*100) / 100; + var zoom = svgZoom(); return { zoom: zoom, devicePxPerCssPx: zoom * devicePixelRatio() @@ -90,7 +105,7 @@ */ var safari= function() { - var zoom = Math.round(((document.documentElement.clientWidth) / window.innerWidth)*100) / 100; + var zoom = svgZoom(); return { zoom: zoom, devicePxPerCssPx: zoom * devicePixelRatio()