当前位置:网站首页>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等其他库
边栏推荐
- HCIP第十一天_MPLS实验
- MySQL8 - use under Windows package installation method
- Nacos source code analysis topic (1) - environment preparation
- AcWing 1053. Repair DNA problem solution (state machine DP, AC automata)
- 2W字!详解20道Redis经典面试题!(珍藏版)
- Chapter 10 聚类
- 第七周复习
- Foundry教程:使用多种方式编写可升级的智能代理合约(下)
- 运维理想和现实,你是?
- Webshell上传方式
猜你喜欢
随机推荐
MySQL中的时区设置
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
WebShell connection tools (Chinese kitchen knife, WeBaCoo, Weevely) use
基于分布式随机森林的火电厂燃烧系统设备建模方法
精益思想如何加速企业的全局价值流动?
三维数字孪生引擎与实景互动,案例解析
JDBC的入门使用
py0_二十一天计划书
MySQL八股文背诵版
1. 获取数据-requests.get()
消息队列经典十连问
R16 Type II量化反馈码本的产生
Using WebShell to get Shell Skills
Difference between #{} and ${}
【无标题】【Koltin Flow(三)】Flow操作符之中间操作符(二)
深度自编码网络的集成学习ICPS入侵检测模型
2W字!梳理50道经典计算机网络面试题(收藏版)
【LeetCode】145. Postorder Traversal of Binary Tree
直击程序员面试现场:百度面试官都问了我些啥?
Go简单实现协程池









