Return to Snippet

Revision: 54215
at December 15, 2011 03:33 by iridium

Initial Code
function orient() {  
    if (window.orientation == 0 || window.orientation == 180) {
    	$("body").attr("class", "portrait");
	orientation = 'portrait';

    	return false;
	else if (window.orientation == 90 || window.orientation == -90) {
    	$("body").attr("class", "landscape");
    	orientation = 'landscape';

    	return false;

/* Call orientation function on page load */

/* Call orientation function on orientation change */
$(window).bind( 'orientationchange', function(e){

Initial URL

Initial Description
This function will detect the orientation (portrait/landscape) of an iOS device and set the body class to either portrait or landscape, as well as providing a global variable for use elsewhere in your JS.

If you require multiple classes on your body tag, simply alter the code to use jQuery's addClass() and removeClass() functions.

Initial Title
iPad/iPhone Orientation Body Class

Initial Tags
css, class, body, iphone, ios

Initial Language