手机端处理布局rem
2024-09-04 13:13:17
方法一
if (document.documentElement.clientWidth > 600) {//页面宽度大于600px让其宽度等于600px,字体大小等于60px,居中
document.documentElement.style.width = "600px";
document.documentElement.style.fontSize = "60px";
document.documentElement.style.margin = "0 auto";
} else {//否则让其根节点字体大小等于宽度/10px
document.documentElement.style.fontSize = document.documentElement.clientWidth / 10 + "px";
}
方法二
; (function (doc, win) {
var html = doc.documentElement, //html
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var hWidth = html.getBoundingClientRect().width;
if (!hWidth) return;
hWidth = Math.min(540, hWidth);
html.style.fontSize = (hWidth / 10) + 'px';
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
recalc();
})(document, window);
最新文章
- 【poj2154】 Color
- Haskell 参考资料
- 获取系统开机的时间(Windows、Linux)
- Linux网络管理——IP地址
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果( dp )
- 笔记28 mssql的update :from语法
- Python3基础 list(reversed()) 将一个列表逆转并输出
- Servlet实现文件上传(多文件)(三)
- 彻底清除Linux centos minerd木马
- gulp总结
- poj1265&;&;2954 [皮克定理 格点多边形]【学习笔记】
- J2EE Exception:WELD-001408 Unsatisfied dependencies for type [SelectModelFactory] with qualifiers [@
- Virtual box中Ubuntu虚拟机磁盘碎片整理和空间清理方法
- oracle分区表的使用和查询
- Maven项目下servlet异常
- centos7 redmine安装过程
- windows设置电脑的固定IP
- 1-安装MQTT服务器(Windows),并连接测试
- keeplived工作原理及配置
- jedisClient操作redis实现增删改查功能
热门文章
- 我的Java开发学习之旅------>Java经典排序算法之归并排序
- (转)source insight 窗口嵌入
- Swift 烧脑体操(四) - map 和 flatMap
- 【Leetcode-easy】Valid Parentheses
- ASP.Net .Net4.0 HTTP 错误 404.17 - Not Found
- Shell 特殊位置参数的变量
- 51Nod 1158 全是1的最大子矩阵 —— 预处理 + 暴力枚举 or 单调栈
- c语言学习的第13天1
- 前端多媒体(1)——获取摄像头&;麦克风
- java面试题05