Css3 perfectly solves mobile phone horizontal and vertical screen judgment, making it easier for users to see invitations
/* Determine the portrait screen of the mobile phone */
@ Media screen and (orientation: portrait ){
/* Css [vertical style definition] */
# Cover1 {display: none; width: 100%; height: 100%; background-color: #000; opacity: 1; position: absolute; z-index: 9999; top: 0px; left: 0px ;}
# Cover1w {display: none; width: 70%; height: 40px; position: absolute; z-index: 10000; top: 50%; left: 15%; margin-top:-20px; font-size: 18px; color: # fff; font-weight: bolder; text-align: center ;}
}
@ Media screen and (orientation: landscape ){
/* Css [horizontally defining styles] */
# Cover1 {display: block; width: 100%; height: 100%; background-color: #000; opacity: 1; position: absolute; z-index: 9999; top: 0px; left: 0px ;}
# Cover1w {display: block; width: 70%; height: 40px; position: absolute; z-index: 10000; top: 50%; left: 15%; margin-top:-20px; font-size: 18px; color: # fff; font-weight: bolder; text-align: center ;}
}
/* PC client or large screen device: 1280px to greater */
@ Media only screen and (min-width: 1280px ){
# Cover1 {display: none; width: 100%; height: 100%; background-color: #000; opacity: 1; position: absolute; z-index: 9999; top: 0px; left: 0px ;}
# Cover1w {display: none; width: 70%; height: 40px; position: absolute; z-index: 10000; top: 50%; left: 15%; margin-top:-20px; font-size: 18px; color: # fff; font-weight: bolder; text-align: center ;}
}
Other reference solutions:
When a user rotates the screen, it enters your monitoring method and obtains the status of the current screen through window. orientation:
0-Portrait Screen
90-rotate the horizontal screen counterclockwise
-90-rotate the horizontal screen clockwise
180-Portrait screen, upside down
If you do not want the user to view your webpage on a horizontal screen, you can use the transition in CSS3 to keep the PAGE vertical in the face of the body in the device rotation time listener.
The page on the mobile device has an orientationchange event when the screen rotates. You can add a listener for this event to the body element:
Js Solution
Today, we will share a jQuery code to help you determine whether a screen is landscape or landscape. Note that the jQuery method is called here, so you need to reference the jQuery class library. Function orient (){
Alert ('gete ');
If (window. orientation = 0 | Windows. orientation = 180 ){
$ ("Body"). attr ("class", "portrait ");
Orientation = 'portrait ';
Return false;
}
Else if (window. orientation = 90 | window. orientation =-90 ){
$ ("Body"). attr ("class", "landscape ");
Orientation = 'landscape ';
Return false;
}
}
$ (Function (){
Orient ();
});
$ (Window). bind ('orientationchang', function (e ){
Orient ();
});
Zookeeper