使用rem进行响应式布局

根据屏幕宽度,动态的去计算html根目录的font-size,来实现响应式rem的效果。

(function() {
var b = document.documentElement,
a = function() {
var a = b.getBoundingClientRect().width;
b.style.fontSize = .0625 * (640 <= a ? 640 : a) + "px"
},
c = null;
window.addEventListener("resize",
function() {
clearTimeout(c);
c = setTimeout(a, 300);
});
a()
})();

a();

 

posted @ 2016-03-01 18:26  骑一头小猪  阅读(246)  评论(0编辑  收藏  举报