Detect viewport orientation, if orientation is Portrait display alert message advising user of instructions
if(window.innerHeight > window.innerWidth){
alert("Please use Landscape!");
}
jQuery Mobile has an event that handles the change of this property... if you want to warn if someone rotates later - orientationchange
Also, after some googling, check out window.orientation
(which is I believe measured in degrees...)
EDIT: On mobile devices, if you open a keyboard then the above may fail, so can use screen.availHeight
and screen.availWidth
, which gives proper height and width even after the keyboard is opened.
if(screen.availHeight > screen.availWidth){
alert("Please use Landscape!");
}
Detect viewport orientation, if orientation is Portrait display alert message advising user of instructions
if(window.innerHeight > window.innerWidth){
alert("Please use Landscape!");
}
jQuery Mobile has an event that handles the change of this property... if you want to warn if someone rotates later - orientationchange
Also, after some googling, check out window.orientation
(which is I believe measured in degrees...)
EDIT: On mobile devices, if you open a keyboard then the above may fail, so can use screen.availHeight
and screen.availWidth
, which gives proper height and width even after the keyboard is opened.
if(screen.availHeight > screen.availWidth){
alert("Please use Landscape!");
}
Detect viewport orientation, if orientation is Portrait display alert message advising user of instructions
if(window.innerHeight > window.innerWidth){
alert("Please use Landscape!");
}
jQuery Mobile has an event that handles the change of this property... if you want to warn if someone rotates later - orientationchange
Also, after some googling, check out window.orientation
(which is I believe measured in degrees...)
EDIT: On mobile devices, if you open a keyboard then the above may fail, so can use screen.availHeight
and screen.availWidth
, which gives proper height and width even after the keyboard is opened.
if(screen.availHeight > screen.availWidth){
alert("Please use Landscape!");
}
Detect device orientation
set a div with a class for the image
<div class="img_a">
Then define the CSS rules for the required images according to orientation or any other media queries you might need to implement
@media screen and (orientation: portrait)
{ div.img_a
{ background: url(https://[...]img_a.jpg) no-repeat fixed; }
[...] }
@media screen and (orientation: landscape)
{ div.img_a
{ background: url(https://[...]img_a_horizontal.jpg) no-repeat fixed; }
[...] }
Related Topics
Create Object from Class Name in Javasscript Ecmascript 6
Browsers, Time Zones, Chrome 67 Error (Historic Timezone Changes)
Node.Js on Multi-Core MAChines
Jquery Load More Data on Scroll
How to Get Form Data with JavaScript/Jquery
Convert String with Commas to Array
How to Download a File with Angular2 or Greater
Truncate Number to Two Decimal Places Without Rounding
Open a New Tab in the Background
What Is the Meaning of the 'G' Flag in Regular Expressions
Emberjs: How to Load Multiple Models on the Same Route
Display Date/Time in User's Locale Format and Time Offset
How to Replace While Loops with a Functional Programming Alternative Without Tail Call Optimization
How to Write a Named Arrow Function in Es2015
What Does "This" Mean in Jquery
Group Objects by Multiple Properties in Array Then Sum Up Their Values
How to Access a JavaScript Object Which Has Spaces in the Object's Key