Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions detect-zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down