• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Screen rotated between portrait and landscape on the fly

 
accnit Jai
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a requirement where I am using the portable device to display my webpage. my webpage is having 3 buttons; button1,button2 and button3 . button1 positioning at right corner of the screen and button2 at left corner of the screen. For button2, on page load i am taking the screen width and placing button2 at the middle of screen. the problem is, if i rotate the device to portrait to landscape then my button2 does not fit to the screen. can you please let me know how we can achieve this using by javascript ? so that button2 should set the position irrespective of screen resolution.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
 
accnit Jai
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eric,

This code achieve my requirement

// check the orientation, on every window.resize event occurs
window.onresize = checkOrientation;

function checkOrientation()
{
// Portrait mode
if(window.innerWidth < window.innerHeight){
alert('Portrait mode: ' + window.innerWidth + 'x' + window.innerHeight);
}
else{
alert('Landscape mode: ' + window.innerWidth + 'x' + window.innerHeight);
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic