/ Published in: JavaScript

Switches body class between .portrait and .landscape for, you guessed it, portrait and landscape mode on the iphone.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; }
URL: http://www.sitepoint.com/article/iphone-development-12-tips/2/
Comments
