| Author |
Screen rotated between portrait and landscape on the fly
|
accnit Jai
Ranch Hand
Joined: Feb 15, 2011
Posts: 33
|
|
|
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
Joined: Nov 08, 2001
Posts: 15362
|
|
http://davidbcalhoun.com/2010/using-mobile-specific-html-css-javascript
Eric
|
 |
accnit Jai
Ranch Hand
Joined: Feb 15, 2011
Posts: 33
|
|
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);
}
}
|
 |
 |
|
|
subject: Screen rotated between portrait and landscape on the fly
|
|
|