Mobile-Adapted Understanding collection

Source: Internet
Author: User

Mobile-related test site: http://kuapingce.com/http://www.cnblogs.com/Charliexie/p/6900640.html1190000008767416 Mobile front-end development of the viewport in-depth understanding

Https://www.cnblogs.com/2050/p/3877280.html

http://www.jianshu.com/p/84c5cb3a485a Some basic concepts windows viewport physical pixels

Device pixels, which are one of the smallest physical parts of a display device. Each pixel can set its own color and brightness based on the operating system.
For the front end, assume that the design is 750px. If the device is a complete display of the 750px width of the design draft. Then the device pixel or the physical pixel is 750px. But maybe the actual width of this device is 375px.

Device independent pixels

Also known as density-independent pixels. Can be thought of as a point in the computer's coordinate system, which represents a virtual pixel (such as a CSS pixel) that can be used by a program and then converted from a related system to a physical pixel.
For the front end: For example, IP6 's device independent pixel is 375px

CSS pixels

CSS pixels are an abstract unit. Mainly used in the browser.
For the front end: How many pixels is the design manuscript.

Screen density

Refers to the number of pixels that exist on a device surface. The average number of pixels in an inch (PPI)

Unit pixel ratio (device pixel RATIO,DPR)

Device pixel ratio = physical pixel/device independent pixel
For example, the physical pixel of iphone6 is 750, the device independent pixel is 375, then its DPR is 2

In JavaScript, you can get the DPR of the current device via Window.devicepixelratio
In CSS, media queries can be made via-webkit-device-pixel-ratio,-webkit-min-device-pixel-ratio,-webkit-max-device-pixel-ratio.

Lemon Club Front-end adaptation scheme

Take IPhone6 as the standard of processing.
The width of the visual manuscript is 750px
Set the font-size of the root element html to 50px so that the 1rem=50px (set to 50 is for ease of calculation)
html{font-size:50px;}
Then the width of the page is 15rem
Use this rule to calculate the width and height of each element of the page
For example, a picture of the width of the height of 100*100
Then the style is written as

img{width:2rem; height:2rem;}

The rem of each element is calculated on the basis of iphone6.

Front-end adaptation

About the processing of font size, using the device independent pixel criteria for the media query

 @media screen and (min-width:320px) {html {font-size:21.33px}body {font-size:12px}} @media screen and (Min-widt h:360px) {html {font-size:24px}body {font-size:12px}} @media screen and (min-width:375px) {html {Font-size:25px}bo dy {font-size:12px}} @media screen and (min-width:384px) {html {font-size:25.6px}body {font-size:14px}} @media scre  En and (min-width:400px) {html {font-size:26.67px}body {font-size:14px}} @media screen and (min-width:414px) {html { font-size:27.6px}body {font-size:14px}} @media screen and (min-width:424px) {html {font-size:28.27px}body {font-s IZE:14PX}} @media screen and (min-width:480px) {html {font-size:32px}body {font-size:15.36px}} @media screen and (min -width:540px) {html {font-size:36px}body {font-size:17.28px}} @media screen and (min-width:720px) {html {font-size : 48px}body {font-size:23.04px}} @media screen and (min-width:750px) {html {font-size:50px}body {font-size:24px} }

In the above media query processing, the corresponding width of the root element html is set a different font-size
For example, when width is 550px, Font-size is 36px. So in this case, just above the IMG element in the case of a page width of 550px is the width should be 72px.
In this scenario, the processing is not related to DPR.
The disadvantage of this scheme is to use the media query to determine the HTML font-size, in such a case, the calculation is not accurate, can only ensure that the general proportional to the normal display of the page. This is not exactly in proportion to the Iphone6-based calculation.
For example, 550px page width, font-size, if the proportion should be 50/750*550 approximately equal to 36.67
600px page width, the font-size should be 40px
And according to this package, the width of the page is 540px to 719px when the font-size are 36px
This can only guarantee the general display in a certain range, is not accurate, and this approximate value of the selection is also each has a view.
Therefore, the above code given in the 11 range of font-size is not necessarily appropriate, the 11 width range is not necessarily appropriate, the actual may not need so much, so find out these ranges, and the most suitable for each range of font-size is also very troublesome.

The adaptation scheme of NetEase

First of all, NetEase is using 640px design draft
Should have been designed with iphone4 or iphone5 as a benchmark.
The benchmark that NetEase uses to calculate REM is 100.
So when the width is 640px=6.4rem

In the adaptation scheme of NetEase, the font-size of HTML is calculated dynamically.
devicewidth=320,font-size=320/6.4=50px---is
320/640*100pxdevicewidth=375,
font-size=375/6.4=58.5975px
And so on calculation
Devicewidth is obtained by document.documentElement.clientWidth and then dynamically computes the font-size of the HTML

If you use this approach, be aware that

<meta name="viewport" content="initial-scale=1,maximum-scale=1, minimum-scale=1">

Because this method has nothing to do with DPR, the current benchmark is calculated based on the device's independent pixels font-size

Lib-flxible Front end Development Terminal adaptation scheme--the adaptation scheme of the hand Amoy lib-flexible Library
<script src="http://g.tbcdn.cn/mtb/lib-flexible/{{version}}/??flexible_css.js,flexible.js"></script>

Implementation ideas
After this JS is executed, a DATA-DPR attribute is added to the HTML (that is, document.documentelement), along with the font-size style. When the page is initially given the meta viewport dynamic

After that, the elements in the page can be set in rem units. The font-size on the HTML is the base pixel of REM.

Flexible the design manuscript into 100 parts, namely 100a,10a=1rem.
For example, the page width is 750px, then a copy is 75px,1rem=75px.
This sets the style of the HTML to

Font-size method: The font-size of the root element HTML is computed by the physical pixel/10.

So its calculation is related to DPR, it can be more accurate to calculate the current width of the root element html font-size. To ensure a more accurate proportional display of the page.
such as the iphone 6 Plus, its DPR is 3, the device independent pixel is 414, so, in the iphone 6 Plus, the HTML font-size should be, 414*3/10=124.2px

The font size is not REM, but the PX is set according to DPR

div{font-size:12px;}[data-dpr=‘2‘]div{font-size:24px;}[data-dpr=‘3‘]div{font-size:36px;}

If INITIAL-DPR is manually set in the meta viewport, it will be forced to assume that DPR is a manually set value regardless of the DPR that JS obtains
So it is not recommended to manually set the value of DPR

Transduction (here refers to the figure is really a graph, need to be scaled) when, to enlarge 1.5 times times the cut, because now there are many like the magic Blue Note this ultra-high-definition screen, Devicepixelratio has reached 3, this cut to ensure that all devices are clearly displayed.



Supersnail
Links: http://www.jianshu.com/p/84c5cb3a485a
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

Mobile-Adapted Understanding collection

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.