Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery Mobile orientationchange Event

jQuery Mobile orientationchange Event

jQuery Mobile Events jQuery Mobile Events

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)".

  • Portrait = the device is rotated in portrait position
  • Landscape = the device is rotated in landscape position
  • |

    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 jQuery Mobile Events