Skip to content

Instantly share code, notes, and snippets.

@veganben
Created August 27, 2013 16:05
Show Gist options
  • Save veganben/6355552 to your computer and use it in GitHub Desktop.
Save veganben/6355552 to your computer and use it in GitHub Desktop.
You don't always need to know which way up a device is being held. You just need to be able to access the values for height and width. This seems to work:
var devicePixelRatio = window.devicePixelRatio || 1,
ww = devicePixelRatio * (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth),
wh = devicePixelRatio * (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
// width, height
var landscape = [Math.max(ww, wh), Math.min(ww, wh)];
var portrait = [Math.min(ww, wh), Math.max(ww ,wh)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment