Easy Tutorial
❮ Jquerymobile Toolbars Event Swipe ❯

jQuery Mobile Orientation Change Event


jQuery Mobile Orientation Change (orientationchange) Event

The orientation change (orientationchange) event is triggered when the user rotates the mobile device vertically or horizontally.

To use the orientation change (orientationchange) event, attach it to the window object:

$(window).on("orientationchange", function() {
    alert("Orientation has changed!");
});

The callback function can have one parameter, the event object, which returns the orientation of the mobile device: "portrait" (device held in vertical position) or "landscape" (device held in horizontal position):

Example

Since the orientation change (orientationchange) event is bound to the window object, we can use the window.orientation property to set different styles to distinguish between portrait and landscape views:

Example

| | The window.orientation property returns 0 for portrait view and 90 or -90 for landscape view. | | --- | --- |

❮ Jquerymobile Toolbars Event Swipe ❯