getBoundingClientRect()方法

getBoundingClientRect 方法 有6个属性 top 、bottom、right、left、width和height
 
ie9以下浏览器只支持 getBoundingClientRect 方法的 top 、bottom、right、left属性;
ie9 和其它浏览器支持 getBoundingClientRect 方法 有6个属性 top 、bottom、right、left、width和height;
根据getBoundClientRect().width这个值来做字体的适配
(function () {
    var html = document.documentElement;

    function onWindowResize() {
        html.style.fontSize = html.getBoundingClientRect().width / 20 + 'px';
    }
    window.addEventListener('resize', onWindowResize);
    onWindowResize();
})();

  

posted @ 2016-08-26 19:02  Y_WEB  阅读(519)  评论(0)    收藏  举报