Mobile-side page adaptation issues

Source: Internet
Author: User

Mobile page full-screen adaptive scheme (using REM as the unit, the design draft is 750 * 1334)

    • Modified from Ali's lib-flexible, compared to lib-flexible, deleted DPR, retains REM
    • Fullscreen adaptive, requires a design draft of 750 * 1334
    • Unit conversion to 1rem = 50px

Code Introduction:

<Head>    <Script>functionRefreshrem () {vare=docel.getboundingclientrect (). Width,t=docel.getboundingclientrect (). Height;if(e/t>750/1334)varI=T/26.68;else var i=e/ the;d ocEl.style.fontSize=I+"px"}varwin=Window,doc=Win.document,docel=Doc.documentelement,tid;win.addeventlistener ("Resize",function() {cleartimeout (tid), Tid=setTimeout (Refreshrem, -)},!1), Win.addeventlistener ("Pageshow",function(e) {e.persisted&&(Cleartimeout (TID), Tid=setTimeout (Refreshrem, -))},!1), Refreshrem ();</Script></Head>

Source

var win = Window;var doc = Win.document;var docel = Doc.documentelement;var tid;function refreshrem () {    var width = doc El.getboundingclientrect (). width;    var height = docel.getboundingclientrect (). Height;    if ((width/height) > (750/1334)) {        var rem = height/(1334/50);    } else {        var rem = width/(750/50 );    }    docEl.style.fontSize = rem + ' px ';} Win.addeventlistener (' Resize ', function () {    cleartimeout (tid);    Tid = SetTimeout (Refreshrem);}, False); Win.addeventlistener (' Pageshow ', function (e) {    if (e.persisted) {        cleartimeout (TID);        Tid = SetTimeout (Refreshrem);    }}, False); Refreshrem ();

Mobile-side page adaptation issues

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.