当前位置:网站首页>The mobile terminal automatically adjusts the page content and font size by setting rem
The mobile terminal automatically adjusts the page content and font size by setting rem
2022-07-07 10:24:00 【weixin_ forty-two million one hundred and seventy-eight thousan】
Mobile end pass setting rem Realize automatic adjustment of page content and font size
function setRem(){
var rem = document.documentElement.clientWidth / 10; // Divide the screen width of the device into ten equal parts
document.documentElement.style.fontSize = rem + "px"; // Set the document root font to the device width 1/10
}
setRem();
window.addEventListener("resize", setRem); // add to resize event , Adjust the document root font size synchronously when the window is adjusted
window.addEventListener("pageShow", function(e) {
// add to pageShow event , Trigger... When the page is displayed
if(e.persisted) {
// Determine whether it is a page fetched from the cache ,true That is, the page fetched from the cache , Trigger the function that sets the root font
setRem();
}
})
pageShow Events and load Events like , All functions are executed when the page is loaded , By clicking on a label ,F5 Refresh and click the forward and backward buttons to refresh the page and execute load event . But Firefox has a round-trip cache , Keep page data and DOM and JS state , That is, the entire page is cached , So clicking back cannot refresh the page , So you can go through pageShow Trigger , Trigger by judging whether it is a page fetched from the cache
边栏推荐
猜你喜欢
ISP、IAP、ICP、JTAG、SWD的编程特点
Socket通信原理和实践
基于HPC场景的集群任务调度系统LSF/SGE/Slurm/PBS
ArcGIS operation: converting DWG data to SHP data
ORM model -- creation and query of data records
【acwing】789. 数的范围(二分基础)
JMeter loop controller and CSV data file settings are used together
JMeter installation
Appx代码签名指南
Embedded background - chip
随机推荐
Es classes and objects, prototypes
Inno Setup 打包及签名指南
ES6中的函數進階學習
BigDecimal数值比较
Fiddler break point
1323:【例6.5】活动选择
Interface test
2022.7.5DAY597
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
Mongodb creates an implicit database as an exercise
MCU is the most popular science (ten thousand words summary, worth collecting)
STM32 ADC and DMA
Postman interface test V
柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?
Kotlin实现微信界面切换(Fragment练习)
PDF文档签名指南
The method of word automatically generating directory
Remote meter reading, switching on and off operation command
Guid primary key
How to cancel automatic saving of changes in sqlyog database