Posted By

ira on 05/02/09


Tagged

javascript iphone


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

cmahoney
brent-man
umang_nine
chrisaiv
VeXHarbinger


Iphone Style Change on Orientation Change


 / Published in: JavaScript
 

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

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

  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. }

Report this snippet  

You need to login to post a comment.