CSS3 Judge mobile phone horizontal screen vertical screen

Source: Internet
Author: User

Principle:

When the user rotates the screen, it goes into your listening method and then window.orientation to get the status of the current screen:
0-Vertical screen
90-Rotate the horizontal screen counterclockwise
-90-rotate the horizontal screen clockwise
180-vertical screen, upside down

If you do not want users to use a horizontal screen view of your page, you can monitor the device rotation time inside the body using CSS3 inside the transition in the rotation to keep the page vertical.

A page on a mobile device that has a Orientationchange event when the screen is rotated. You can increase the listener for this event to the BODY element:

<body onorientationchange= "updateorientation (); >

Monitor form changes to monitor phone screen

@media screen and (orientation:portrait) {

css[vertical definition Style]

}

@media screen and (Orientation:landscape) {

css[horizontal definition Style]

}

CSS3 Judge mobile phone horizontal screen vertical screen

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.