Mobile-side layout rem

Source: Internet
Author: User

/* # to set the HTML font according to the wide-height ratio, width=device-width initial-scale=1 # @pargam Win window Windows object # @pargam option{DESIGNWI DTH: Design manuscript width, must designheight: Design draft height, do not preach the proportion according to the width to calculate, optional designfontsize: Design draft for the calculation of font size, default 20, Optional callback: Font calculation    After the callback function, optional} # return Boolean; # PS: Please try to run this JS computing font */!function (win, option) {var count = 0, Designwidth = option.designwidth, Designheigh t = Option.designheight | | 0, designfontsize = option.designfontsize | | callback = Option.callback | |  NULL, root = document.documentelement, BODY = document.body, rootwidth, newSize, t, self; Returns the root element font calculation result function _getnewfontsize () {var scale = Designheight!== 0?    Math.min (Win.innerwidth/designwidth, win.innerheight/designheight): win.innerwidth/designwidth;  return parseint (Scale * 10000 * designfontsize)/10000;    }!function () {rootwidth = Root.getboundingclientrect (). width; Self = self?    Self:arguments.callee; If this screenIf the width is not accurate, try to get the resolution again, try only 20 times, otherwise use win.innerwidth to calculate if (rootwidth!== win.innerwidth && count <) {win.se        Ttimeout (function () {count++;      Self ();    }, 0);      } else {newSize = _getnewfontsize (); If the CSS is already compatible with the current resolution regardless of if (newSize + ' px '!== getcomputedstyle (root) [' font-size ']) {root.style.fontSize = NewS        ize + "px";      Return callback && callback (newSize);    };  };  }(); Change the fontsize when the screen is switched, choose to use Win.addeventlistener ("Onorientationchange" in window as needed).    "Orientationchange": "Resize", function () {cleartimeout (t);    t = setTimeout (function () {self ();  }, 200); }, False);} (window, {designwidth:750,//designheight:960, designfontsize:100, callback:function (argument) {//console . log (argument)}});

  

Mobile-side layout rem

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.