JS set root node (HTML) font-size font size based on device width

Source: Internet
Author: User

JS set root node (HTML) font-size font size based on device width

(function () {

Document.addeventlistener (' domcontentloaded ', function () {

var devicewidth = document.documentElement.clientWidth;

Document.documentElement.style.fontSize = devicewidth/6.4 + ' px ';

}, False);

Window.onresize = function () {

var devicewidth = document.documentElement.clientWidth;

Document.documentElement.style.fontSize = devicewidth/6.4 + ' px ';

};

})();

Http://baoxian.pingan.com/pa18shopnst/u/wx/product/bankCardSafe/index.shtml

1190000004189237?_ea=522147


Http://caibaojian.com/flexible-js.html

Http://caibaojian.com/web-app-rem.html

Http://huodong.m.taobao.com/act/yibo.html

Http://121.40.99.17/global/rem-phone.html



Head pixel

<script type= "Text/javascript" >

var scale = 1.0, ratio = 1, Assetshost = ' g.tbcdn.cn ', assetsversion = ' 0.5.12 ', istestenv = false;

(function () {

if (Location.host.match (/(Waptest|wapa) \.taobao\.com$/i)) {

Assetshost = ' g.assets.daily.taobao.net ';

assetsversion = ' 0.5.12 ';

Istestenv = true;

}

if (window.devicepixelratio = = = 2 && window.navigator.appVersion.match (/iphone/gi)) {

scale = 0.5;

Ratio = 2;

}

var text = ' <meta name= ' viewport "content=" initial-scale= ' + scale + ', maximum-scale= ' + scale + ', minimum-scale= ' + S Cale + ', User-scalable=no '/> '

+ ' <link ' + ' type= "text/css" rel= "StyleSheet" href= "http//' + assetshost + '/mtb/app-index/' + assetsversion + '/index ' + ratio + '. css ' + '/> ';

document.write (text);

})();

</script>


JS set root node (HTML) font-size font size based on device width

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.