JS Sets the root node (HTML) font size based on the width of the device

JS Sets the root node (HTML) font size based on the width of the device

(function () {

   document.addEventListener(‘DOMContentLoaded’, function () {

var deviceWidth = document.documentElement.clientWidth;

Document. The documentElement. Style. FontSize = deviceWidth / 6.4 + ‘px’;

   }, false);

window.onresize = function(){

var deviceWidth = document.documentElement.clientWidth;

Document. The documentElement. Style. FontSize = deviceWidth / 6.4 + ‘px’;

};

}) ();

Baoxian.pingan.com/pa18shopnst…

Segmentfault.com/a/119000000…

Caibaojian.com/flexible-js…

Caibaojian.com/web-app-rem…

Huodong.m.taobao.com/act/yibo.ht…

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

The head of pixels

<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=’ + scale + ‘, user-scalable=no” />’

        + ‘<link’ + ‘ type=”text/css” rel=”styleSheet” href=”http://’ + assetsHost + ‘/mtb/app-index/’ + assetsVersion + ‘/index’ + ratio + ‘.css”‘ + ‘ />’;

document.write(text);

}) ();

</script>