A section of JS code that automatically scales the iphone when you prevent the screen from being vertically

Source: Internet
Author: User

function Orientation_change () {var viewport = Document.queryselector (' meta[name= "viewport"] '); if (window.orientation = = 0 | | window.orientation = =) Viewport.setattribute ("Content", "Width=device-width, Max    imum-scale=1.0, initial-scale=1.0, User-scalable=no "); else if (window.orientation = = -90 | | window.orientation = =) Viewport.setattribute ("Content", "Width=device-heig     HT, maximum-scale=1.0, initial-scale=1.0, User-scalable=no "); }window.onorientationchange = Orientation_change;

  

Window.orientation
: This property gives the screen orientation of the current device, 0 for the vertical screen, plus and minus 90 for the horizontal screen (left and right) mode

Onorientationchange
: This window event is triggered when the screen orientation is switched between the horizontal and vertical screens, using the same usage as the traditional event

#b {width:300px;height:200px;background:blue;} @media screen and (orientation:portrait) {#b {background:red;}} @media screen and (Orientation:landscape) {#b {background:green;}}

  

A section of JS code that automatically scales the iphone when you prevent the screen from being vertically

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.