javascript - Displaying different data through portrait/landscape view -


is there way of handling when user turns portrait landscape view on web application? when looking web app on portrait view , see normal data. stocks app on ios, portrait view

and when turn device landscape view see different data. stocks app on ios, landscape view

my question: there way of accomplishing pure javascript , css? or have rely on api?

update: found way of doing pure/plain js using device orientation api , i've found example accomplishes i'm trying can't make work because if statement interrupting me every time rotation greater 90 , if put variable check if rotation 90.

function init() {         var compass = document.getelementbyid('compass'),         comp = document.getelementbyid("comp");         if(window.deviceorientationevent) {            window.addeventlistener('deviceorientation', function(event) {                 var alpha;                 //check ios property                 if(event.webkitcompassheading) {                   alpha = event.webkitcompassheading;                   //rotation reversed ios                   compass.style.webkittransform = 'rotate(-' + alpha + 'deg)';                 }                 //non ios                 else {                   alpha = event.alpha;                   webkitalpha = alpha;                   if(!window.chrome) {                     //assume android stock (this crude, enough our example) , apply offset                     webkitalpha = alpha-270;                   }                 }                  compass.style.transform = 'rotate(' + alpha + 'deg)';  //this part i've added var iftrue = false; comp.innerhtml = alpha + "deg"; if (alpha >= 90 && alpha <= 100) {     if (!iftrue) {         alert("it is");         return iftrue = true;     }; } else if (alpha <= 90) {console.log("it not"); }; //till here                    compass.style.webkittransform = 'rotate('+ webkitalpha + 'deg)';                 //rotation reversed ff                 compass.style.moztransform = 'rotate(-' + alpha + 'deg)';                }, false);         }       } 

you can use css media queries detect, if device in landscape- or portrait. css can define information show when. example:

/* ----------- iphone 6+ ----------- */ /* portrait , landscape */ @media screen   , (min-device-width: 414px)   , (max-device-width: 736px)   , (-webkit-min-device-pixel-ratio: 3) {  /* styles */ }  /* portrait */ @media screen   , (min-device-width: 414px)   , (max-device-width: 736px)   , (-webkit-min-device-pixel-ratio: 3)  , (orientation: portrait) {   /* styles */ }  /* landscape */ @media screen   , (min-device-width: 414px)   , (max-device-width: 736px)   , (-webkit-min-device-pixel-ratio: 3)  , (orientation: landscape) {   /* styles */ } 

see https://css-tricks.com/snippets/css/media-queries-for-standard-devices/ more examples.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -