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

Nacos source code analysis topic (1) - environment preparation

第二章——堆栈、队列

ASP WebShell 后门脚本与免杀

Go语学习笔记 - gorm使用 - gorm处理错误 Web框架Gin(十)

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

JunitTest单元测试

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

WebShell connection tools (Chinese kitchen knife, WeBaCoo, Weevely) use

ROS2自学笔记:launch文件完整编写流程

Nacos source code analysis topic (2) - service registration
随机推荐
MySQL8.0.26安装配置教程(windows 64位)
三维数字孪生引擎与实景互动,案例解析
面试必备!TCP协议经典十五连问!
一种基于行为空间的回声状态网络参数优化方法
MySQL index optimization in practice
【无标题】【Koltin Flow(三)】Flow操作符之中间操作符(二)
消息队列经典十连问
精益思想如何加速企业的全局价值流动?
DVWA安装教程(懂你的不懂·详细)
* Compare version numbers
MySQL函数(经典收藏)
Invalid bound statement (not found)出现的原因和解决方法
Chapter 10_Index Optimization and Query Optimization
常见的SQL面试题:经典50例
1. 获取数据-requests.get()
7-43 字符串关键字的散列映射 (25 分) 谜之测试点
利用WebShell拿Shell技巧
Common SQL interview questions: 50 classic examples
PHP WebSehll backdoor script and detection tool
mysql8.0.28 download and installation detailed tutorial, suitable for win11