Iphone Style Change on Orientation Change


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. window.addEventListener('load', setOrientation, false);
  2. window.addEventListener('orientationchange', setOrientation, false);
  3.  
  4. function setOrientation() {
  5. var orient = Math.abs(window.orientation) === 90 ? 'landscape' : 'portrait';
  6. var cl = document.body.className;
  7. cl = cl.replace(/portrait|landscape/, orient);
  8. document.body.className = cl;
  9. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.