Skip to content

Instantly share code, notes, and snippets.

@brianswisher
Created September 23, 2011 23:00
Show Gist options
  • Save brianswisher/1238678 to your computer and use it in GitHub Desktop.
Save brianswisher/1238678 to your computer and use it in GitHub Desktop.
A mobile web dev script to toggle through portrait & landscape classes on a document's body element.
/*global document */
var orientation;
(function () {
"use strict";
orientation = function () {
var isPortrait, isLandscape;
isPortrait = document.body.className.indexOf('portrait') !== -1;
isLandscape = document.body.className.indexOf('landscape') !== -1;
document.body.className = document.body.className.split(' portrait ').join('');
document.body.className = document.body.className.split(' landscape ').join('');
if (!isPortrait && !isLandscape) {
document.body.className += ' portrait ';
} else if (!isLandscape) {
document.body.className += ' landscape ';
}
};
orientation();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment