当前位置:网站首页>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等其他库
边栏推荐
猜你喜欢
随机推荐
2022年最新一篇文章教你青龙面板拉库,拉取单文件,安装依赖,设置环境变量,解决没有或丢失依赖can‘t find module之保姆教程(附带几十个青龙面板脚本仓库)
浏览器的工作原理(dns域名服务器,tcp握手,ssl/tls安全协议,关键渲染路径,重绘及回流,防抖和节流)
自定义mvc框架复习(crud)
生成器知道鉴别器在无条件GANs中应该学习什么
【LeetCode】1374. Generate a string with an odd number of each character
dropout
PHP WebSehll 后门脚本与检测工具
OperatingSystemMXBean to get system performance metrics
合奥科技网络 面试(含参考答案)
深度学习:目标检测入门知识
【LeetCode】144. Preorder Traversal of Binary Tree
基于分布式随机森林的火电厂燃烧系统设备建模方法
Invalid bound statement (not found)出现的原因和解决方法
[LeetCode] 83. Delete duplicate elements in the sorted list
py0_二十一天计划书
什么是轮式里程计
Chapter 10 聚类
Lua安装及常用命令使用
MySQL8.0.28安装教程
Nacos source code analysis topic (1) - environment preparation