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:
Comments
One Response to “window.orientation and the orientationchange event vs Modernizr.mq orientation”
Leave a Reply
You must be logged in to post a comment.
October 18th, 2014 @ 1:39 pm
window.orientation and the orientationchange event vs Modernizr.mq orientation | Relax Breath of Solution.