What is lib-flexible?
lib-flexible is an open source library for making H5 adaptation, you can download the relevant files here and get the JavaScript and CSS files you need.
How to use
Introduction of JS file in head tag
<src= "Build/flexible_css.debug.js"></script> <src= "Build/flexible.debug.js"></Script >
You can also use Ali's CDN:
<src= "http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??" Flexible_css.js,flexible.js "></script>
It is also strongly recommended to do inline processing of JS, before all resources are loaded to execute this JS. After this JS is executed, an attribute is added to the element data-dpr , along with a font-size style. JS will add different values depending on the device, for data-dpr example 2 3 , or, at the same time, the corresponding value will be added html , for font-size example75px。
Using in Projects
When the design draft is 750px
Usage in less (75 refers to the font-size reference size of the HTML tag when the device used at development is IPhone6):
{ . P2R (@px) { return: unit (@px/75, 1rem); } }
Less using a custom function requires plug-in support, depending on the https://github.com/seven-phases-max/less-plugin-functions
Then you can use this:
{ width: p2r (100px); height: p2r (100px); }
For example, when IPhone6, the HTML tag is added DATA-DPR property, and the base value Font-size
The width and height of the div are 100/75rem=1.33333333rem
At IPhone6 Plus, the DATA-DPR is 3
The DIV's rem is still 1.3333333rem, but since the Font-size reference value of the HTML tag becomes 124.2, the width and height of the div are not 100px.
In this way, when the DPR and resolution of the device are not the same, the elements will change in size accordingly, thus achieving the effect of adapting to different devices.
Reference: Use flexible to achieve the end of H5 page adaptation
Mobile multi-terminal adaptation scheme--lib-flexible