码迷,mamicode.com
首页 > 移动开发 > 详细

移动端设置-----rem

时间:2016-02-24 12:24:48      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

对于现在不同尺寸的移动端屏幕,如果设置px来说实在有点影响用户体验,在小屏幕上太大,大屏幕上太小,不能实现响应式,所以就引进了rem的概念。

rem是相对于根元素<html>

在我的项目中就是用这样的一段js代码。

 

(function () {

var resizeEvt = ‘orientationchange‘ in window ? ‘orientationchange‘ : ‘resize‘;

var recalc = function () {

var clientWidth = document.body.clientWidth;

if(!clientWidth){

return;

}

document.documentElement.style.fontSize = 10 * (clientWidth/320)+ ‘px‘;

document.documentElement.style.visibility = ‘visible‘;

}

if(!document.documentElement.addEventListener){

return;

}

window.addEventListener(resizeEvt,recalc,false);

window.addEventListener(‘DOMContentLoaded‘,recalc,false);

})();

 

当设计给我psd时,测量文字为40px,html使用rem值=40/20=2rem。

rem其实不单只能使用在文字的单位,还可以用于height,width,padding,marigin,line-height等的单位。

移动端设置-----rem

标签:

原文地址:http://www.cnblogs.com/matthew9298-Begin20160224/p/5212114.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!