Set the JS code for the root font

Source: Internet
Author: User

The mobile side often involves using REM to lay out, so it's important to set the root font. Here is the JS code to set the root font, for reference only!

1(function(Doc, win) {2     varDocel =Doc.documentelement,3resizeevt = ' Orientationchange 'inchWindow? ' Orientationchange ': ' Resize ',4Recalc =function () {5             varClientWidth =Docel.clientwidth;6             if(!clientwidth)return;7             if(clientwidth>=640){8docEl.style.fontSize = ' 100px ';9}Else{TenDocEl.style.fontSize = + * (clientwidth/640) + ' px 'The //640 is the width of the design, which now seems to be 750.  One             } A         }; -  -     if(!doc.addeventlistener)return; theWin.addeventlistener (Resizeevt, Recalc,false); -Doc.addeventlistener (' domcontentloaded ', Recalc,false); -}) (document, window);

I hope you are the great God!

Set the JS code for the root font

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.