Relax Breath of Solution.Community tech blog of Sameera Thilakasiri - Consultant UI, UX, RWD Specialist/ Interactive Designer

Just I wanted.. Do you?…

window.orientation and the orientationchange event vs Modernizr.mq orientation

Posted on October 22, 2012 | 1 Comment

Luckily on the latest smartphones you have some goodies available to you that you don’t have on the desktop (since desktop users aren’t in the habit of constantly turning their screens sideways!).

window.orientation: this property gives the current screen orientation: 0 in portrait mode, 90 when rotated left, -90 when rotated right (no special value when the screen is upside-down)

orientationchange event: this window event fires after every 90 degrees of rotation and, like other events, can be applied in various ways:

    // DOM Level 0 (avoid)  
    window.onorientationchange = function(){};  
      
    // DOM Level 2  
    window.addEventListener('orientationchange', function(){}, false);  

Orientation change using Modernizr

 
	if(typeof Modernizr != "undefined" && Modernizr.mq('(orientation: portrait)')){
		//alert('portrait');
	}
	else if(typeof Modernizr != "undefined" && Modernizr.mq('(orientation: landscape)')){
		//alert('landscape');
	}

Incoming search terms:

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

Comments

One Response to “window.orientation and the orientationchange event vs Modernizr.mq orientation”

  1. Thale
    October 18th, 2014 @ 1:39 pm

    window.orientation and the orientationchange event vs Modernizr.mq orientation | Relax Breath of Solution.

Leave a Reply

You must be logged in to post a comment.