// 移动端响应式匹配 px转rem=20
(function () {
document.addEventListener('DOMContentLoaded', function () {
var html = document.documentElement;
var windowWidth = html.clientWidth;
html.style.fontSize = windowWidth / 96 + 'px';
}, false);
})();
window.onload=function(){
document.addEventListener(
"DOMContentLoaded",
function() {
var deviceWidth = document.documentElement.clientWidth;
document.documentElement.style.fontSize = deviceWidth / 96 + "px";
},
false
);
window.onresize = function() {
var deviceWidth = document.documentElement.clientWidth;
document.documentElement.style.fontSize = deviceWidth / 96 + "px";
};
}
移动端响应式布局匹配 px转rem
最新推荐文章于 2024-08-22 11:06:05 发布
本文介绍如何使用JavaScript为移动端页面实现px到rem的转换,确保在不同设备上保持一致的字体大小,通过DOMContentLoaded和window.onload事件监听器以及onresize调整元素尺寸。
摘要由CSDN通过智能技术生成