Mobile multi-terminal adaptation scheme--lib-flexible

Source: Internet
Author: User

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

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.