Css3 perfectly solves mobile phone horizontal and vertical screen judgment, making it easier for users to see invitations

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.