This code is for animations to be executed as long as the width of the browser or viewport is between 480 and 800 pixels:
if ( window.innerWidth > 480 && window.innerWidth < 800 ) {
//aqui vienen 200 lineas de codigo de animaciones
}
So far so good. The problem is that if a user enters with a mobile of 450 wide and 600 high, and turns it 90 degrees, its width changes to 600, but my animations would not work although they would be within the range of my conditional, because initially the user I enter with a width of 450 (which is below 480), and when I rotated it did not update the page, so the scripts
would not be executed unless he updates the web (which is unlikely). This would give me errors. Animations would not work if users rotated with their phones or tablets.
Then what I can think of is to make a conditional that specifies that, when I am between 480 and 800 in PORTRAIT (vertical) AND ALMOST when I am between 480 and 800 in LANDSCAPTE (horizontal) I apply the animations.
But I have never used the ORIENTATION property of javascript
, and since my website is still local (on a laptop) I do not have to prove that the orientation works correctly, so I need you to do me the favor of reviewing the following code and confirm that it is correct, according to what I want to do:
if (window.innerWidth > 480 && window.innerWidth < 800 && window.orientation == 0
||
window.innerWidth > 480 && window.innerWidth < 800 && window.orientation == 90) {
}
Is it correct? Or if you have a better way, please help me by putting the code. Thanks.