移动端pic转rem

1.

window.onload = function () {
getRem( 750, 100 )
};
window.onresize = function () {
getRem( 750, 100 )
};
function getRem( pwidth, prem ) {
var html = document.getElementsByTagName( "html" )[0];
var oWidth = document.body.clientWidth || document.documentElement.clientWidth;
html.style.fontSize = oWidth / pwidth * prem + "px";
}

750屏幕宽,7.5rem相当于750px, 设计稿同比缩放
posted @ 2018-04-02 09:27  米牙  阅读(256)  评论(0编辑  收藏  举报