当前位置:网站首页>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等其他库
边栏推荐
猜你喜欢

Chapter 10_Index Optimization and Query Optimization

PHP WebShell Free Kill

mysql使用on duplicate key update批量更新数据

Lua安装及常用命令使用

利用WebShell拿Shell技巧

Navicat cannot connect to database Mysql because of WiFi

暴力破解全攻略

mysql8.0.28 download and installation detailed tutorial, suitable for win11

1. 获取数据-requests.get()

第七周复习
随机推荐
WebShell Feature Value Summary and Detection Tool
Chrome浏览器无法加载已解压的.crx文件的解决办法
【LeetCode】102. Level order traversal of binary tree
Heuristic merge, DSU on Tree
【遥控器开发基础教程3】疯壳·开源编队无人机-ADC(摇杆控制)
7-36 社交网络图中结点的“重要性”计算 (30 分) 不用迪杰斯特拉也不用弗洛伊德
ModuleNotFoundError: No module named ‘openpyxl‘
Go语学习笔记 - gorm使用 - gorm处理错误 Web框架Gin(十)
Common SQL interview questions: 50 classic examples
第二章——堆栈、队列
弹性盒子flex属性
分布式事务解决方案模型
MySQL修改最大连接数限制
一种基于行为空间的回声状态网络参数优化方法
Chapter 11_Database Design Specifications
8万字带你入门Rust
ASP WebShell backdoor script and anti-kill
第一章——线性表(顺序表和链表)
VPS8702 VPSC(源特科技)电源管理(PMIC) 封装SOT23-6
IPIDEA的使用方式