Then slowly know the 1th is due to the retina screen device pixel than the problem caused by the 2nd known unit REM.
Do not want to use REM to calculate the size of the design manuscript, design 750 of the dimensions of the dimension can be used directly in the sass, the font does not use REM scaling, because:
Another goal is to dynamically set the page when it is not set viewport, and to not let the page have a "flash" process (that is, the state that has just been loaded is not set to the state of the setting); When the page changes dynamically, the size changes accordingly;
When writing the H5 page, write the meta tag as little as possible, and I'll do it:
This is simple, and the Code of implementation is, of course, placed in the head. Because there is no written viewport, so the judgment plus
if (!metael) { Metael = doc.createelement (' meta '); Metael.setattribute (' name ', ' viewport '); Metael.setattribute (' content ', ' width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, User-scalable=no '); if (docel.firstelementchild) { docEl.firstElementChild.appendChild (Metael); } else { var wrap = Doc.createelement (' div '); Wrap.appendchild (Metael); Doc.write (wrap.innerhtml); }}
Then zoom according to the devicepixelratio of the page
var scale = parsefloat ((1/DPR). toFixed (2)), if (DPR! = 1) { metael.setattribute (' content ', ' width=device-width, Initial-scale= ' + scale + ', maximum-scale= ' + scale + ', minimum-scale= ' + scale + ', User-scalable=no ');}
Set the root font size
Document Widthfunction Setdocumentfontsize () { var width = docel.getboundingclientrect (). width; DocEl.style.fontSize = width/10 + ' px ';} Setdocumentfontsize ();
Page Resize Monitoring
var timer;win.addeventlistener (' Resize ', function () { cleartimeout (timer); Timer = setTimeout (function () { setdocumentfontsize (); }, +);}, False);
For fonts that do not use REM, you need to set the DATA-DPR property for DocumentElement
Document DATA-DPR set font-size pxvar DPR = window.devicepixelratio;if (devicepixelratio >= 3 && (!DPR | | dp R >= 3)) { DPR = 3;} else if (Devicepixelratio >= 2 && (!DPR | | DPR >= 2)) { DPR = 2;} else { DPR = 1;} Docel.setattribute (' DATA-DPR ', DPR);
Sass Related Settings
Written entirely according to the design manuscript size
Basefontsize $baseFontSize: @function px2rem ($px) { @return $px/$baseFontSize * 1REM;} @function px2rem2 ($px) { @return Px2rem ($px);}
Font size Change
Font size calculation @mixin FONT-DPR ($font-size) { font-size: $font-size; [data-dpr= "2"] & { font-size: $font-size * 2; } [data-dpr= "3"] & { font-size: $font-size * 3; }}
Example: a simple style setting
. Test { @include FONT-DPR (10px); WIDTH:PX2REM2 (+); margin:0 Auto; border:1px #dcdcdc Solid;} img { display:block; WIDTH:PX2REM2 (355); margin:0 Auto;}
Examples of effects:
As can be seen, the 6p DPR is 3, the font corresponding to 30px, the page scaled 3 times times, formally I want.
Page demo Source
<! DOCTYPE html>Welcome to follow my blog: http://ymblog.net
Mobile self-adaptive layout scheme attempt