viewport : literally means a view window, used in mobile web development. Indicates that the device browser width is virtual into a specific value (or calculated) so that the mobile web site is basically consistent across device display. Basic wording: <meta name= "viewport" content= "Width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, target-densitydpi=medium-dpi "> Test get viewport width : Document.documentElement.clientWidth1, iphone is read device-width value, and automatically calculates target-densitydpi to fit, the value read on iphone4 is 320 . The final formula is: When initial-scale=1 :viewportwidth=width ; when initial-scale!=1 When: Viewportwidth=width > 320/initial-scale? Width:320/initial-scale; viewportwidth not more than 1280 , more than fetch 1280 . 2, in android , reading is target-densitydpi . In the case of not setting, the default selection is medium-dpi . The following discussion is on the screen size of the phone on the range of:dpi 's rating and its corresponding representation resolution:low-dpi:240*320 (basic elimination, not discussed) medium-dpi:320*480high-dpi:480* 800Super high-dpi:640*960 it to dpi for 120 , 160 , 240 , 320 . Experiment one: Set dpi for medium-dpi  for 480*800 , and its viewport 320 ; set to &NBSP;HIGH-DPI&NBSP;&NBSP, whose viewport is set to device-dpi   for 480 ;, and its viewport for 480 ; experiment Two: to 540*800 set medium-dpi , viewport to 360 ; is set to &NBSP;HIGH-DPI&NBSP;&NBSP, and its viewport is 540 ; set to device-dpi The viewport is set to 540 ; for &NBSP;LOW-DPI&NBSP;&NBSP, and its viewport is 270 Summary: From the above two experiments can be drawn: when the device is high-dpi device, set to medium resolution viewportwidth for ( 2/3 ) * When device-width ; is set to low-dpi , *device-width is ( 1/2 ). This ratio is consistent with its dpi ratio, 2/3=160/240 and 1/2=120/240 ; conjecture dpi values with viewportwidth There is a unary relationship. ① Suppose I'm going to do a android high-dpi device application, virtual viewportwidth dead for 320px . Set device-width=x , ( 2/3 ) *x set the device to medium-dpi when viewportwidth The value of , x/240 represents how many px a dpi value represents. target-densitydpi=160-{ ( 2/3 ) *x-320}/(x/240); simplified: target-densitydpi=320*240/x ; experiment Three: Set &NBSP;TARGET-DENSITYDPI=142&NBSP on 540 phone, viewport 320 . According to the above formula, we can calculate the target-densitydpi=142.222222 , which is consistent with the above test data. ② Suppose I want to do a android super-high-dpi device application, virtual viewportwidth dead 320px . target-densitydpi=320*320/x ; This formula has not been validated for a trial period. ③ Suppose I want to do a android medium-dpi device application, virtual viewportwidth dead 320px . target-densitydpi=160-{x-320}/(x/160); target-densitydpi=320*160/x Experimental Success ④ Suppose I'm going to do a android low-dpi device application, virtual viewportwidth dead 320px . target-densitydpi=160-{ ( 4/3 ) x-320}/(x/120); Target-densitydpi=320*120/x This formula has not been validated for a trial period. Exception: htca510e : in width Reads width  when there is a specific value, ignoring dpi . Lenovo k1 pad does not read dpi , and only reads width , and when width is less than equals 320 is ignored, Direct access to device-width . 3, HTC input scaling problem. When the value of viewport is greater than device-width , the input get focus magnification appears. So in the design choose based on 320 resolution ( 240 device elimination is not discussed), the plot is based on 640 , picture 0.5 zoom guarantee sharpness.
Summary, in the development of the best based on the 320 wide development, the picture is based on 640, in the picture can be placed with background-size or zoom zoom one times, the picture on the high-definition screen will not blur. By reading the width of the device to calculate the DPI and dynamically generate META tags when loading the page, the resolution adaptation of the phone can be solved well. But on Android pad side does not apply, for two, one, pad to width is calculated or read more chaotic, some like iOS, some read dpi, and some two are read, and then segmented comparison. Second, the pad High School low DPI sub-file and mobile phone is not the same, there is no unified standard
The viewport of the experience of mobile terminal design and development