JavaScript rem.js(rem 自适应屏幕大小)
- 使用方法:设计稿得到尺寸除以 100 就是 rem 值
;(function(){
var html = document.documentElement,
resizeEvent = 'orientationchange' in window ? 'orientationchange' : 'resize',
dW = 750;
function remCalc(){
var clientW = html.clientWidth;
if(!clientW) return;
if(clientW > dW){
html.style.width = dW + 'px';
html.style.fontSize = '100px';
html.style.margin = '0 auto';
}else{
html.style.fontSize = clientW / dW * 100 + 'px';
}
}
if(!html.addEventListener) return;
window.addEventListener(resizeEvent,remCalc,false);
document.addEventListener('DOMContentLoaded',remCalc,false);
})()
js