Wednesday, October 20, 2010

Screen orientation handling in iphone/android

var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";

//adding event listener
window.addEventListener(orientationEvent, function() {
var orientation = window.orientation;
switch(orientation) {
case 0:
//your code goes here.
break;

case 90: //landscapeLeft
case -90: //landscapeRight
//your code goes here.
break;
}

}, false);

No comments:

Post a Comment