The viewport of the experience of mobile terminal design and development

Source: Internet
Author: User

viewport&nbsp: 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&nbsp, 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&nbsp for  480*800 , and its  viewport   320 ; set to &NBSP;HIGH-DPI&NBSP;&NBSP, whose  viewport  is set to  device-dpi &nbsp 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&nbsp, ( 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&nbsp, 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&nbsp when there is a specific value, ignoring  dpi . Lenovo  k1 pad   does not read  dpi&nbsp, and only reads  width&nbsp, 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

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.