当前位置:网站首页>rem适配
rem适配
2022-08-02 03:07:00 【小叶_01】
- 为什么做 rem 适配
a) 机型太多,不同的机型屏幕大小不一样
b) 需求: 一套设计稿的内容在不同的机型上呈现的效果一致,根据屏幕大小不同的变化,页面中的内容也相应变化 - rem和em区别
rem: (root em),rem是css中的一种相对长度单位。
相对于根元素(即 html元素)font-size计算值的倍数
em是相对于父标签元素 - 实现1:
function remRefresh() {
let clientWidth = document.documentElement.clientWidth; // 将屏幕等分 10 份
let rem = clientWidth / 10;
//document.documentElement即是html
document.documentElement.style.fontSize = rem + 'px';
document.body.style.fontSize = '12px';
}
window.addEventListener('pageshow', () => {
remRefresh()
})
// 函数防抖
let timeoutId;
window.addEventListener('resize', () => {
timeoutId && clearTimeout(timeoutId);
timeoutId = setTimeout(() =>{
remRefresh()
}, 300)
})
补充也可以在html文件中配合媒体查询设计html元素
@media screen and (min-width: 320px) {
html {
font-size: 21.33px;
}
}
@media screen and (min-width: 750px) {
html {
font-size: 50px;
}
}
- 实现2:
第三方库实现lib-flexible + px2rem-loader等其他库
边栏推荐
- 【LeetCode】206. Reverse linked list
- MySQL index optimization in practice
- VPS8504C 微功率隔离电源隔离芯片 VPSC源特科技
- MySQL8--Windows下使用msi(图形界面)安装的方法
- 22-08-01 西安 尚医通(01)跨域配置、Swagger2、R类、统一异常处理和自定义异常、Logback日志
- ROS2自学笔记:launch文件完整编写流程
- ModuleNotFoundError: No module named ‘openpyxl‘
- 消息队列经典十连问
- Recursively check if a configuration item has changed and replace it
- 合奥科技网络 面试(含参考答案)
猜你喜欢
JSP WebSehll 后门脚本
深度学习:目标检测入门知识
"Paid paddling" stealthily brushes Brother Ali's face scriptures, challenges bytes three times, and finally achieves positive results
WebShell连接工具(中国菜刀、WeBaCoo、Weevely)使用
知识体系树
PHP WebShell 免杀
ASP WebShell backdoor script and anti-kill
IPIDEA的使用方式
Chapter 10_Index Optimization and Query Optimization
嵌入式分享合集25
随机推荐
生成器知道鉴别器在无条件GANs中应该学习什么
程序员的七夕浪漫时刻
Kubernetes 基本概念
VPS8701 电源管理(PMIC) VPS8701
【LeetCode】1374. 生成每种字符都是奇数个的字符串
svm.SVC application practice 1--Breast cancer detection
【LeetCode】102. Level order traversal of binary tree
AcWing 1053. Repair DNA problem solution (state machine DP, AC automata)
【LeetCode】83.删除排序链表中的重复元素
一种基于行为空间的回声状态网络参数优化方法
PHP WebShell Free Kill
* Compare version numbers
DVWA安装教程(懂你的不懂·详细)
leetcode 143. 重排链表
第一章——线性表(顺序表和链表)
01-Node-Express系统框架搭建(express-generator)
【LeetCode】104. Maximum depth of binary tree
Nacos source code analysis topic (2) - service registration
Reasons and solutions for Invalid bound statement (not found)
[Daily LeetCode]——1. The sum of two numbers