当前位置:网站首页>rem adaptation
rem adaptation
2022-08-02 03:15:00 【Leaflet_01】
- 为什么做 rem 适配
a) 机型太多,不同的机型屏幕大小不一样
b) 需求: 一套设计稿的内容在不同的机型上呈现的效果一致,根据屏幕大小不同的变化,页面中的内容也相应变化 - rem和em区别
rem: (root em),rem是cssA unit of relative length in .
相对于根元素(即 html元素)font-size计算值的倍数
emis relative to the parent tag element - 实现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)
})
Supplements can also behtmlThe file is designed with media querieshtml元素
@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等其他库
边栏推荐
- 2W字!梳理50道经典计算机网络面试题(收藏版)
- Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
- 【LeetCode】1374. Generate a string with an odd number of each character
- CV-Model【4】:MobileNet v3
- 基于优化的多核局部费舍尔判别分析的故障分类
- PHP WebShell Free Kill
- 7、MySQL Workbench 导出导入数据库
- Foundry教程:使用多种方式编写可升级的智能代理合约(下)
- JSP WebSehll backdoor script
- PHP WebShell 免杀
猜你喜欢
随机推荐
C语言力扣第47题全排列 II。搜索回溯
精益思想如何加速企业的全局价值流动?
基于分布式随机森林的火电厂燃烧系统设备建模方法
Navicat cannot connect to database Mysql because of WiFi
聊聊flink的BoundedOutOfOrdernessTimestampExtractor
MySQL修改最大连接数限制
Double Strings (别总忘记substr)
Good Key, Bad Key (思维,临项交换,经典方法)
【无标题】【Koltin Flow(三)】Flow操作符之中间操作符(二)
Webshell上传方式
2W字!详解20道Redis经典面试题!(珍藏版)
# ODS及DWD层自动化构建##, 220731,
EF Core:基于关系的复杂查询 区分IEnumerable和IQueryable
【LeetCode】104. Maximum depth of binary tree
Webshell upload method
Day34 LeetCode
TRICK第二弹
Chapter 10_Index Optimization and Query Optimization
Heuristic merge, DSU on Tree
7-42 整型关键字的散列映射 (25 分)









