function Orientation_change () {var viewport = Document.queryselector (' meta[name= "viewport"] '); if (window.orientation = = 0 | | window.orientation = =) Viewport.setattribute ("Content", "Width=device-width, Max imum-scale=1.0, initial-scale=1.0, User-scalable=no "); else if (window.orientation = = -90 | | window.orientation = =) Viewport.setattribute ("Content", "Width=device-heig HT, maximum-scale=1.0, initial-scale=1.0, User-scalable=no "); }window.onorientationchange = Orientation_change;
Window.orientation
: This property gives the screen orientation of the current device, 0 for the vertical screen, plus and minus 90 for the horizontal screen (left and right) mode
Onorientationchange
: This window event is triggered when the screen orientation is switched between the horizontal and vertical screens, using the same usage as the traditional event
#b {width:300px;height:200px;background:blue;} @media screen and (orientation:portrait) {#b {background:red;}} @media screen and (Orientation:landscape) {#b {background:green;}}
A section of JS code that automatically scales the iphone when you prevent the screen from being vertically