JS makes the mobile terminal auto scaling display, js makes auto Scaling

Source: Internet
Author: User

JS makes the mobile terminal auto scaling display, js makes auto Scaling

JS makes a mobile terminal adaptive scaling display

Example 1:

<script>var _width = parseInt(window.screen.width);var scale = _width/640;var ua = navigator.userAgent.toLowerCase();var result = /android (\d+\.\d+)/.exec(ua);if (result){var version = parseFloat(result[1]);if(version>2.3){document.write('<meta name="viewport" content="width=640, minimum-scale = '+scale+', maximum-scale = '+scale+', target-densitydpi=device-dpi">');}else{document.write('<meta name="viewport" content="width=640, target-densitydpi=device-dpi">');}} else {document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');}</script>

Example 2:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script><script type="text/javascript">$(function(){ if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {  var viewportmeta = document.querySelector('meta[name="viewport"]');   if (viewportmeta) {    viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';  document.addEventListener('touchstart', function () {   viewportmeta.content = 'viewportmeta.content = width=device-width, minimum-scale=0.25, maximum-scale=1.6';  }, false);   document.addEventListener('orientationchange', function () {   viewportmeta.content = 'viewportmeta.content = width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';  }, false);   }  }});</script>

Example 3:

<meta charset="UTF-8"><meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"><meta content="yes" name="apple-mobile-web-app-capable"><meta content="black" name="apple-mobile-web-app-status-bar-style"><meta content="telephone=no" name="format-detection">

Summary:

I. In fact, it is not difficult. First, add a line of viewport meta tag to the header of the webpage code.

<Meta name = "viewport" content = "width = device-width, initial-scale = 1"/>

2. Do not use absolute width because the webpage will adjust the layout according to the screen width, so you cannot use an absolute width layout or an element with an absolute width.

3. The relative font size cannot use absolute size (px), but can only use relative size (em ).

4. fluid grid indicates that the positions of each block are floating, not fixed.
. Main {float: right; width: 70%;}. leftBar {float: left; width: 25% ;}

5. In addition to layout and text, fluid image must automatically scale the image as well as "Adaptive webpage design.

The above is all the content of this article. I hope you will like it.

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.