JS根据设备宽度设置根节点(html)font-size字体大小

时间:2016-05-03 16:19:49   收藏:0   阅读:4098

JS根据设备宽度设置根节点(html)font-size字体大小

(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

https://segmentfault.com/a/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



头部像素

<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>


评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!