首页 > 移动平台 > 详细

编辑手机页面rem的使用

时间:2017-01-01 15:20:32      阅读:291      评论:0      收藏:0      [点我收藏+]

手机rem的使用只需加入如下代码:

针对最大宽度为480px使用如下代码
<script >
var html = document.getElementsByTagName("html")[0];
var rootResize = function() {
    var winClient = document.documentElement.clientWidth;
    var fontSize = winClient < 480 ? winClient / 16 : 30;
    if (fontSize < 20) {
        fontSize = 20;
    }
    html.style.fontSize = fontSize + "px";
}
rootResize();
window.onresize = function() {
    rootResize();
</script>
针对最大宽度为640px使用如下代码
        <script>
var html = document.getElementsByTagName("html")[0];
var rootResize = function() {
var winClient = document.documentElement.clientWidth;
var fontSize = winClient < 640 ? winClient / 16 : 40;
if (fontSize < 20) {
fontSize = 20;
}
html.style.fontSize = fontSize + "px";
}
rootResize();
window.onresize = function() {
rootResize();
}
</script>

编辑手机页面rem的使用

原文:http://www.cnblogs.com/bkysgj/p/6240999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!