1 回答
TA贡献8条经验 获得超1个赞
!new function(){var a=this;a.width=750,a.fontSize=100,a.widthProportion=function(){var b=(document.body&&document.body.clientWidth||document.getElementsByTagName("html")[0].offsetWidth)/a.width;return b>1?1:b},a.changePage=function(){document.getElementsByTagName("html")[0].setAttribute("style","font-size:"+a.widthProportion()*a.fontSize+"px !important")},a.changePage(),window.addEventListener("resize",function(){a.changePage()},!1)};
示例代码:
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<head>
/*每个页面都需要引入rem.js 代码如上*/
<script src="js/rem.js"></script>
<style>
/*设计图中div的宽度为750px 高度为100px*/
div{width: 7.5rem;height: 1rem;}
</style>
</head>
<body>
<div>内容</div>
</body>
</html>
添加回答
举报