Disable the user Autoscale feature: <meta name= "viewport" content= "Width=device-width, initial-scale=1.0, maximum-scale=1.0, User-scalable=0 "> Judge the state of vertical and horizontal screen There are two ways: CSS judgment, JS Judgment (a), CSS to judge the screen or portrait screen 1, written in the same CSS file
@media screen and (orientation:portrait) { /* vertical css*/} @media screens and ( Orientation:landscape) { /* cross-screen CSS*/}
Depending on the size of the screen, normal page size can be written in general, horizontal screen style is set separately. Just add a horizontal screen style based on the original style,
@media screen and (Orientation:landscape) {/ * horizontal css*/}
The default style is loaded when the horizontal screen style is loaded while the user is horizontal, and the horizontal screen style is removed when the screen is vertical.
2, separate write in two CSS, according to the screen to refer to different style files:
referencing different style files according to the screen
Horizontal screen:
<link rel="stylesheet" media="All and(orientation:landscape)" href="Landscape. css">
Vertical screen:
<link rel="stylesheet" media="All and(orientation:portrait)" href="portrait.css">
Note:CSS Judge screen is always seamless, that is, horizontal screen loading horizontal screen style, vertical screen loading vertical screen style,
(b) JS judge the horizontal screen or vertical screen
//determine the status of the phone screen:Window.addeventlistener ("Onorientationchange" inchWindow?"Orientationchange":"Resize", function () {if(Window.orientation = = = the|| Window.orientation = = =0) {Console.log ("Vertical Screen"); $(". codeig_s"). Removeclass ('Vercreen');//Remove a horizontal screen style } if(Window.orientation = = = -|| Window.orientation = = =- -) {Console.log ("Horizontal Screen"); $(". codeig_s"). AddClass ('Vercreen');//Add a horizontal screen style } }, false);
Note: The horizontal screen style in the Vercreen class name modifies the original default style, can be used normally, the disadvantage is that there must be a toggle state screen to trigger.
If the user by default is the horizontal screen state does not trigger the horizontal screen condition judgment, only the user from the horizontal screen to vertical screen or from the vertical screen to a horizontal screen will trigger the corresponding conditions to judge.
Without switching state will not perform any condition judgment, here is not as good as CSS to judge the overall screen.
Mobile phone to determine the status of the screen