移动端px转换rem

function setHtmlFont(){
    var html = document.documentElement;
    window.rem = html.getBoundingClientRect().width / 750 *100;
    html.style.fontSize = window.rem + 'px';
}

setHtmlFont();

window.addEventListener('resize', function () {
	setHtmlFont();
})

//例如font-size:24px写成font-size=0.24rem

posted @ 2021-03-02 16:43  可不可以重名  阅读(33)  评论(0编辑  收藏  举报