jQuery Mobile orientationchange Event
Example
Some text pops up when the user flips the mobile device:
$(window).on("orientationchange",function(){
alert("Direction changed!");
});
Try it »
Definition and Usage
The orientationchange event is triggered when the user flips the device horizontally or vertically (i.e., the orientation changes).
**Note:** To see the effect of the orientationchange event, users must use a mobile device or mobile emulator to view this site's example.
Syntax
$(window).on("orientationchange",function(event){...})
| Parameters | Description |
|---|---|
| function(event) | Required. Specifies the function to execute after the orientationchange event is triggered.
To determine which direction the device is rotated, you can access the orientation property, whose value can be "portrait (vertical)" or "landscape (horizontal)". |
More examples
Event Object
Use event.orientation to return the orientation of the mobile device.
Window object
Use the window.orientation property to set different styles between "portrait (vertical)" and "landscape (horizontal)".
jQuery Mobile Events