当前位置:网站首页>Common solutions for mobile terminals
Common solutions for mobile terminals
2022-07-01 05:29:00 【CV engineer with brain】
1、resize monitor
var resizeTimer = null;
$(window).resize(function(){
if(resizeTimer){
clearTimeout(resizeTimer);
}
resizeTimer = setTimeout(function(){
console.log(" Window changes ")
},100)
})
2、ResizeObserver
Listen for changes in element width
const objResizeObserver = new ResizeObserver(entries => {
const entry = entries[0];
// dom attribute
const cr = entry.contentRect;
setTimeout(() => {
const distanceW = Math.abs(cr.width - oldScreen.width) > 100;
load = cr.width === window.innerWidth;
if (distanceW && load) {
load = false;
oldScreen.width = window.innerWidth;
onOrientation();
} else {
onResizeRem();
}
}, 100);
});
Monitor different devices
const ua = useUa();
const isLark = /lark/i.test(ua);
const isIpad = /ipad/i.test(ua);
const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
Flying book ipad
if (isLark && isIpad && isTouch)
Monitor horizontal and vertical screen switching
window.addEventListener('orientationchange', onOrientation);
Handle root font size changes
export const useRem = (): void => {
// const [rem, setRem] = useState<number>(100);
function setRem() {
// setRem((window.innerWidth / 414) * 100);
const fontSize = (window.innerWidth / 375) * 100;
document.documentElement.style.fontSize = `${
fontSize}px`;
}
useEffect(() => {
setRem();
window.addEventListener('resize', setRem);
window.addEventListener('orientationchange', onOrientation);
return () => {
window.removeEventListener('resize', setRem);
window.removeEventListener('orientationchange', onOrientation);
document.documentElement.style.fontSize = '16px';
};
}, []);
};
Monitor the font size of the mobile phone
Set the root font size change to useEffect Inside
Can cause , Page initialization display , The root font has not been calculated yet
The problem that elements shrink first and then enlarge
At the head of the page
for example react
<Helmet>
<script>{
SCRIPT_CONTENT}</script>{
' '}
</Helmet>
On mobile phone ,
No compatible horizontal screen , Therefore, it is expected that the root font size of the horizontal screen and the vertical screen
iPad not so bad
const ua = useUa();
const isAnd = /android/i.test(ua);
// const isIphone = /iphone/i.test(ua);
const isIpad = /ipad/i.test(ua);
const isIpadsafari = ua.includes('Safari') && !ua.includes('iPhone');
const isMobile = isIpad || (isIpadsafari && !isAnd);
const SCRIPT_CONTENT = `document.documentElement.style.fontSize = ${
isMobile ? window.innerWidth : 375
} / 375 * 100 + "px";`;
ua
const isMobile = /(ipad|iphone|ipod|windows phone|android)/i.test(navigator.userAgent);
边栏推荐
- Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
- Cockroachdb: the resistant geo distributed SQL database paper reading notes
- C WPF uses dockpanel to realize screenshot box
- Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards
- Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
- LevelDB源码分析之memtable
- 第05天-文件操作函数
- Printk debugging summary
- [RootersCTF2019]babyWeb
- 複制寶貝提示材質不能為空,如何解决?
猜你喜欢

JDBC常见面试题

CockroachDB: The Resilient Geo-Distributed SQL Database 论文阅读笔记

tar命令

Memtable for leveldb source code analysis

Unity project experience summary

How to hide browser network IP address and modify IP internet access?

LRU cache for leveldb source code analysis

Application of industrial conductive slip ring

Use and principle of reentrantlock

Design and application of immutable classes
随机推荐
Global and Chinese market for instant messaging security and compliance solutions 2022-2028: Research Report on technology, participants, trends, market size and share
Detailed explanation of set
[data recovery in North Asia] a data recovery case of raid crash caused by hard disk drop during data synchronization of hot spare disk of RAID5 disk array
AcWing 888. Finding combinatorial number IV (the problem of finding combinatorial number with high precision)
What can the points mall Games bring to businesses? How to build a points mall?
如何开始学剪辑?零基础详细解析
Unity项目心得总结
Global and Chinese markets for business weather forecasting 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of broadband amplifiers 2022-2028: Research Report on technology, participants, trends, market size and share
数据库连接池的简单实现
Receiving package install and uninstall events
Global and Chinese markets of InGaAs APD arrays 2022-2028: Research Report on technology, participants, trends, market size and share
[SRS] use of Vhost isolated stream: push / pull Stream Address
How to start learning editing? Detailed analysis of zero basis
Copy baby prompt: material cannot be empty. How to solve it?
Unity 使用Sqlite
小程序常用组件小结
Printk debugging summary
Rust基础入门之变量绑定与解构
0xc000007b应用程序无法正常启动解决方案(亲测有效)