Viewport:
First, viewport is actually to render your entire page into a larger proportion of viewport inside, by zooming lets you see the entire page. iOS has a viewport of 980px. Android is not necessarily, there is 640px 1000px or larger.
The width of the default viewport for browsers on some devices is as follows:
In fact, when you look at a page like this on a mobile device, the phone browser does two things for us by default:
(1), render the page in a 980px (IOS) viewport inside
(2), after rendering, by zooming let us see the entire page of the full picture.
Some people might say, "That's just the right scaling." That's because by zooming a 1000-megapixel page into a 300-megapixel screen, the layout will go out of shape and it will often look ugly. So in order to typeset correctly, introduced the viewport, first let the typesetting correct then zooms to the mobile device screen.
second, viewport generally divided into three viewport: layout viewport, visual viewport and ideal viewport
1, layout viewport, on the phone, in order to accommodate the desktop browser design site, the default layout viewport width. Note that it is not the width of the page, and iOS defaults to 980px. We can get the value of the layout viewport by Document.documentElement.clientWidth.
2. Visual viewport, as wide as the screen width, represents the size of the viewable area of the browser, but its number of CSS pixels will change as the user zooms in. You can also understand scaling scale for a window. Note that it is not the width of the device. We can get the value of visual viewport through Window.innerwidth.
3, ideal viewport is the most suitable for mobile device viewport, width is equal to the screen width of mobile devices. The meaning of ideal viewport is that, regardless of the resolution of the screen, those designed for the ideal viewport site, do not need the user manual scaling, and do not need to appear horizontal scroll bar, can be perfectly presented to the user. We can get the value of the ideal viewport by Screen.width.
Third, why don't we use the default layout viewport?
1) width is not controllable. Different systems may have different default values for different devices. For example, Android may have 640,1000 or larger.
2) reduced page display, unfriendly
3) Link not point
4) There is a zoom, there is a scroll bar after zooming.
Iv. META Tags
<meta name= "viewport" content= "width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0, User-scalable=no ">
Width: Sets the widths of the layout viewport, as a positive integer, or the string "Device-width"
Initial-scale: Sets the initial zoom value of the page, which is a number that can be taken with decimals
Minimum-scale: Allows the user's minimum zoom value, which is a number that can be taken with decimals
Maximum-scale: Allows the user's maximum zoom value, which is a number that can be taken with decimals
User-scalable: Whether to allow the user to zoom, the value is "no" or "yes", no is not allowed, yes means allow
Initial-scale: Sets the initial zoom value of the page. The first thing to figure out is how the scaling is scaled relative to what it is, and the answer is to scale with the ideal viewport, and the larger the zoom value, the smaller the current visual viewport will be, and vice versa. For example, in the iphone, the ideal width of the viewport is 320px, if we set the initial-scale=2, the width of the visual viewport will become only 160px, this is understood, magnified one times, is the original 1px of things into 2px, However, 1px to 2px is not the original 320px into 640px, but in the actual width of the case, 1px has become the same length as the original 2px, so zoom in twice times after the original need 320px to fill the width now only need 160px to do. Therefore, we can draw a formula:
Visual viewport = Ideal viewport/Current zoom value
Current Zoom value = Ideal viewport/Visual viewport
Current ZOOM value = Screen.width/window.innerwidth
On the iphone and ipad, no matter how wide you set the viewport, if you don't specify a default scaling value, the iphone and ipad will automatically calculate this scaling value to reach the current page without a horizontal scroll bar (or viewport width is the width of the screen). The purpose.
In summary, if I do not give the set Initial-scale value, the device will automatically adjust the zoom ratio according to the size of your page, so the visual Viewprot under different devices will be different, this is not the result we want, so we put initial-scale=1, To unify the zoom ratio, let our visual viewport equals the device Viewprot.
So our perfect notation is:
<meta name= "viewport" content= "Width=device-width,initial-scale=1.0,user-scalable=no" >
Mobile Web Learning Notes (ii)