!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)};
每個頁面都需要引入rem.js 代碼如上兼贸,如果設(shè)計圖中div的寬度為750px 高度為100px
示例代碼:
<script src="js/rem.js"></script>
<style>
div{width: 7.5rem;height: 1rem;}
</style>
<div>內(nèi)容</div>