您的位置:首页 > 移动开发

移动端rem文字自适式

2017-09-06 19:34 183 查看
<script type="text/javascript">
(function (doc, win) {
//  html
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
clientWidth = (clientWidth > 768 ) ? 768 : clientWidth ; docEl.style.fontSize = 10 * (clientWidth / 375 ) + 'px';
};
if (!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false);
recalc();
})(document, window);
/*移动端适应大小*/
</script>


<div class="div-1"> ahahhhah </div>


.div-1{
width:250px;
height:250px;
background-color: red;
font-size:1.6rem;
}


直接粘贴运行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: