当前位置:网站首页>移动端通过设置rem使页面内容及字体大小自动调整
移动端通过设置rem使页面内容及字体大小自动调整
2022-07-07 08:10:00 【weixin_42178670】
移动端通过设置rem实现页面内容及字体大小自动调整
function setRem(){
var rem = document.documentElement.clientWidth / 10; // 把设备屏幕宽度十等分
document.documentElement.style.fontSize = rem + "px"; // 把文档根字体设置成设备宽度的1/10
}
setRem();
window.addEventListener("resize", setRem); // 添加resize事件,当窗口调整时同步调整文档根字体大小
window.addEventListener("pageShow", function(e) {
// 添加pageShow事件,在页面显示时触发
if(e.persisted) {
// 判断是否是缓存中取的页面,true即是缓存中取的页面,触发设置根字体的函数
setRem();
}
})
pageShow事件和load事件一样,均是加载页面时即执行函数,通过点击a标签,F5刷新以及点击前进后退按钮均可刷新页面并执行load事件。但火狐有个往返缓存,保留页面数据以及DOM和JS状态,也就是说整个页面均被缓存,所以点击后退也不能刷新页面,所以可以通过pageShow触发,通过判断是否是缓存中取的页面来进行触发
边栏推荐
- The Himalaya web version will pop up after each pause. It is recommended to download the client solution
- Prototype object in ES6
- Fiddler simulates the interface test
- [higherhrnet] higherhrnet detailed heat map regression code of higherhrnet
- JMeter loop controller and CSV data file settings are used together
- Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
- .NET配置系统
- Es classes and objects, prototypes
- ORM -- query type, association query
- Differences between MCU and MPU
猜你喜欢
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
Smart city construction based on GIS 3D visualization technology
Leetcode exercise - 113 Path sum II
Postman interface test V
The new activity of "the arrival of twelve constellations and goddesses" was launched
ES类和对象、原型
Appx代碼簽名指南
Serial communication relay Modbus communication host computer debugging software tool project development case
柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?
每周推荐短视频:L2级有哪些我们日常中经常会用到的功能?
随机推荐
高数_第1章空间解析几何与向量代数_向量的数量积
A wave of open source notebooks is coming
@Transcation的配置,使用,原理注意事项:
.NET配置系统
Why is the reflection efficiency low?
The Himalaya web version will pop up after each pause. It is recommended to download the client solution
Programming features of ISP, IAP, ICP, JTAG and SWD
Serial communication relay Modbus communication host computer debugging software tool project development case
The new activity of "the arrival of twelve constellations and goddesses" was launched
ORM model -- creation and query of data records
ORM -- query type, association query
2022.7.6DAY598
Fiddler break point
单片机(MCU)最强科普(万字总结,值得收藏)
Appx代碼簽名指南
The landing practice of ByteDance kitex in SEMA e-commerce scene
ArcGIS operation: batch modify attribute table
STM32 Basics - memory mapping
fiddler-AutoResponder
JMeter about setting thread group and time