当前位置:网站首页>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 market for instant messaging security and compliance solutions 2022-2028: Research Report on technology, participants, trends, market size and share
- 基于TI DRV8424驱动步进电机实现调速和行程控制
- Txncoordsender of cockroachdb distributed transaction source code analysis
- Redis数据库的部署及常用命令
- Rust基础入门之变量绑定与解构
- Use and principle of Park unpark
- How to start learning editing? Detailed analysis of zero basis
- Things generated by busybox
- Unity project experience summary
- More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv.so‘.
猜你喜欢
How to meet the requirements of source code confidentiality and source code security management
Leetcode top 100 questions 1 Sum of two numbers
数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化
Use and principle of reentrantlock
Design and application of immutable classes
Daily code 300 lines learning notes day 11
CockroachDB 分布式事务源码分析之 TxnCoordSender
Use and principle of AQS related implementation classes
Explanation of characteristics of hydraulic slip ring
基于TI DRV8424驱动步进电机实现调速和行程控制
随机推荐
el-cascader回显失败;el-cascader回显不出来
Explanation of characteristics of hydraulic slip ring
QDataStream的簡單讀寫驗證
Use and principle of wait notify
LRU cache for leveldb source code analysis
Thread process foundation of JUC
Global and Chinese market for instant messaging security and compliance solutions 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of solder wire 2022-2028: Research Report on technology, participants, trends, market size and share
Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
实战:redux的基本使用
Dynamic verification of new form items in El form; El form verifies that the dynamic form V-IF does not take effect;
Understand several related problems in JVM - JVM memory layout, class loading mechanism, garbage collection
HDU - 1024 Max Sum Plus Plus(DP)
Flutter 实现每次进来界面都刷新数据
液压滑环的特点讲解
[SRS] use of Vhost isolated stream: push / pull Stream Address
eBPF Cilium实战(2) - 底层网络可观测性
Vmware workstation network card settings and three common network modes
Web Security (IX) what is JWT?