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

Small program (necessary common sense for development) 1

Nacos source code analysis topic (1) - environment preparation

mysql8.0.28下载和安装详细教程,适配win11

DVWA安装教程(懂你的不懂·详细)

消息队列经典十连问

面试必备!TCP协议经典十五连问!

01-Node-Express系统框架搭建(express-generator)

(转帖)HashCode总结(2)

Nacos source code analysis topic (2) - service registration

浏览器的工作原理(dns域名服务器,tcp握手,ssl/tls安全协议,关键渲染路径,重绘及回流,防抖和节流)
随机推荐
HCIP第十一天_MPLS实验
7-35 城市间紧急救援 (25 分)c语言(测试点二未通过)
一个资深测试工程师面试一来就问我这些题目
HCIP Day 11_MPLS Experiment
利用WebShell拿Shell技巧
MySQL8.0.26 installation and configuration tutorial (windows 64-bit)
PHP WebShell 免杀
总体写作原则
JSP Webshell 免杀
Double Strings (别总忘记substr)
考虑饱和的多智能体系统数据驱动双向一致性
CentOS7安装Oracle数据库的全流程
MySQL8 -- use msi (graphical user interface) under Windows installation method
第一章——线性表(顺序表和链表)
8万字带你入门Rust
MySQL六脉神剑,SQL通关大总结
2W字!详解20道Redis经典面试题!(珍藏版)
Nacos source code analysis topic (1) - environment preparation
消息队列经典十连问
两对象数组比较拿出不同值方法