web analytics

How to detect mobile device orientation change in jquery?

Options

codeling 1595 - 6639
@2019-12-28 12:31:10

How can we detect orientation changes on the mobile devices such smart phones, tablets? The jQuery Mobile orientationchange event is fired when the user rotates the mobile device vertically or horizontally.

$(window).on( "orientationchange", function( event ) {

   alert("This device is in " + event.orientation + " mode!" )

});

@2019-12-28 12:40:09

Aslo you can identify orientation by CSS media queries as well:

/* portrait */
@media screen and (orientation:portrait) {
/* portrait-specific styles */
}

 

/* landscape */
@media screen and (orientation:landscape) {
/* landscape-specific styles */
}

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com