Determine horizontal screen and vertical screen (3) and horizontal screen

Source: Internet
Author: User

Determine horizontal screen and vertical screen (3) and horizontal screen

When you create a mobile page, you often need to determine whether the screen is landscape or landscape. We will record the currently known judgment methods through HTML, CSS, and JS to facilitate future reading.

1. reference the landscape and landscape styles in html:

<Link rel = "stylesheet" media = "all and (orientation: portrait) "href =" portrait.css "rel =" external nofollow "> // reference the CSS of the portrait screen <link rel =" stylesheet "media =" all and (orientation: landscape) "href =" landscape.css "rel =" external nofollow "> // reference the CSS of the landscape

2. Use the media query method in CSS to judge:

@ Media (orientation: portrait) {// landscape CSS} @ media (orientation: landscape) {// landscape CSS}

3. js checks whether the screen is landscape or portrait:

Window. addEventListener ("onorientationchange" in window? Orientationchange ":" resize ", function () {if (window. orientation = 180 | window. orientation = 0) {alert ('portrait screen status! ');} If (window. orientation = 90 | window. orientation =-90) {alert ('landscape status! ') ;}}, False );

The onorientationchange event is triggered as long as the user changes the viewing mode of the device.

Orientation has four values: 0, 90,-90,180

When the values are 0 and 180, It is a portrait screen (180 is a reverse portrait screen );

Horizontal screen at the time of 90 and-90 (-90 is the reverse portrait mode );

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

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.