Skip to content

Commit

Permalink
Webkit Mobile: use orientation to choose device width from screen.(wi…
Browse files Browse the repository at this point in the history
…dth|height)
  • Loading branch information
skeltoac committed Jun 27, 2012
1 parent e9df8c7 commit 4aa9ccc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions detect-zoom.js
Expand Up @@ -65,10 +65,16 @@ var DetectZoom = {
},
_zoomWebkitMobile: function() {
// the trick: window.innerWIdth is in CSS pixels, while
// documentElement.clientWidth is in system pixels.
// screen.width and screen.height are in system pixels.
// And there are no scrollbars to mess up the measurement.
var z = document.documentElement.clientWidth / window.innerWidth;
var devicePixelRatio = window.devicePixelRatio != null ? window.devicePixelRatio : 1;
var devicePixelRatio = window.devicePixelRatio != null ? window.devicePixelRatio : 1
, deviceWidth;
if ( Math.abs(window.orientation) == 90 ) {
deviceWidth = screen.height;
} else {
deviceWidth = screen.width;
}
var z = deviceWidth / window.innerWidth;
// return immediately; don't round at the end.
return {zoom: z, devicePxPerCssPx: z*devicePixelRatio};
},
Expand Down

0 comments on commit 4aa9ccc

Please sign in to comment.