Window.devicepixelratio
This read-only property returns the ratio of the resolution in physical pixels to the resolution in CSS pixel s for the current display device.
The value is the ratio between resolutions, not directly comparing pixels. Resolution refers to the number of pixels in inches, similar to the PPI.
The value of DPR in the PC-side browser is 1, so the 1px elements in the CSS Occupy 1 of the physical pixels in the screen.
But on the phone side, because of the high split screen, physical pixels and CSS logic pixels are not 1:1 of the relationship. For example, the DPR in IPhone5 is 2, that is, 2 physical pixels correspond to 1 logical pixels.
In addition, scaling also alters this correspondence.
Viewport
The width of the
Document.documentelement.clientwidth,gives the Dimensionsof the viewport, and not of the
Screen.width: The size of the screen. You ' re isn't interested in the physical size ofthe screens, but what many CSS pixels currently fit on it.
Media queries: Use different styles for elements of different sizes.
Web developers is not interested in the devicewidth; It's the width of the browser window that counts. So use width and forgetdevice-width-on desktop.
Mobile phone side
Mobile browser vendors want to offer theirclients the best possible experience, which right now means "as much likedesktop As possible. " That,however, requires viewport to is split into two:the visual viewport and Thelayout viewport. (The concept of virtual layout viewport is introduced in order to display the content of the website on a PC browser normally on a mobile device.) )
The visual viewport is Thepart of the page that's currently shown on-screen. The user may scroll to changethe part of the page he sees, or zoom to change the size of the visualviewport.
How wide is the layout viewport? that Differsper browser. Safari IPhone uses 980px, Opera 850px, Android WebKit 800px, Andie 974px. So the content of the PC page can also be browsed on the phone, but it will only shrink very small.
You can change the orientation of the frame (visual viewport), but the size andshape of the large image (layout viewport) n Ever changes.
Zooming
Many mobile browsers initially show any page infully zoomed-out mode. Most browsers zoom out to show the entire layoutviewport on the screen. Browsers has chosen their dimensions of the layoutviewport such that it completely covers the screens in fully zoomed-out Mode (and is thus equal to the visual viewport). Thus the width and the height ofthe layout viewport is equal to whatever can is shown on the screens in themaximally zoome D-out mode. When the user zooms in these dimensions stay thesame.
Measuring the visual viewport
Visual viewport, it's measured by window.innerWidth/Height , it shows how many CSS pixels currently fit on the screen. Obviously the measurements change when the user is zooms out or in, since more orfewer CSS pixels fit to the screen.
Event coordinates
pageX/Yis still relative to the page in CSS pixels.
screenX/YclientX/Yis relative to the screens in device Pixels,this was the same reference that uses, and device pixels are useless.
Meta Viewport
<metaname="viewport" content="width=320">
It's meant to resize the layout viewport. Because the default layoutviewport on the mobile side is larger than the visualviewport, the META tag controls the properties of the Layoutviewport to achieve better display results.
When you set Width=device-width, the layout viewport is as wide as the visual viewport, but the screen zooms to a certain ratio to show everything.
Zoom (zoom) and move operations are controlled by Visualviewport;
Layoutviewport once it is initialized, it will not change; you can control layoutviewport through the properties of the META tag.
Apple 6 Display effect (auto refresh is often a problem when you test with chrome, preferably click Toggledevice Toolbar view)
Apple 6 has a DPR of 2 and a physical resolution of 1334*750, so the visual viewport can display 375 css pixels in width.
When Meta is not set, safari default layout viewport is 980px and 980px is displayed if the width of the page is less than the width of layoutviewport. Otherwise, safari shrinks the zoom out page until all layout viewport is displayed in Visual point.
If you set the width and set the Initail-scale, it will be scaled to the appropriate scale, with no scroll bar.
If you set the initial-scale=1.0 again, it will not be scaled, resulting in a scroll bar to display all the content by moving:
Excerpted from a tale of the Viewports, the concepts are very clear.
Viewport properties on the phone side