Return to Snippet

Revision: 13680
at May 2, 2009 13:57 by ira


Initial Code
window.addEventListener('load', setOrientation, false);
window.addEventListener('orientationchange', setOrientation, false);

function setOrientation() {
 var orient = Math.abs(window.orientation) === 90 ? 'landscape' : 'portrait';
 var cl = document.body.className;
 cl = cl.replace(/portrait|landscape/, orient);
 document.body.className = cl;
}

Initial URL
http://www.sitepoint.com/article/iphone-development-12-tips/2/

Initial Description
Switches body class between .portrait and .landscape for, you guessed it, portrait and landscape mode on the iphone.

Initial Title
Iphone Style Change on Orientation Change

Initial Tags
javascript, iphone

Initial Language
JavaScript