当前位置:网站首页>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 of 3D CAD 2022-2028: Research Report on technology, participants, trends, market size and share
- Vérification simple de la lecture et de l'écriture de qdatastream
- 如何选择导电滑环材料
- Rainbow combines neuvector to practice container safety management
- Global and Chinese market of enterprise wireless LAN 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
- Unity 使用Sqlite
- Global and Chinese market of solder wire 2022-2028: Research Report on technology, participants, trends, market size and share
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- AcWing 888. Finding combinatorial number IV (the problem of finding combinatorial number with high precision)
猜你喜欢

eBPF Cilium实战(2) - 底层网络可观测性

Understand several related problems in JVM - JVM memory layout, class loading mechanism, garbage collection

工业导电滑环的应用

Leetcode1497- check whether array pairs can be divided by K - array - hash table - count

Summary of spanner's paper

Practice of combining rook CEPH and rainbow, a cloud native storage solution

Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards

0xc000007b the application cannot start the solution normally (the pro test is valid)

Use and principle of reentrantlock

LevelDB源码分析之LRU Cache
随机推荐
Global and Chinese market of paper machine systems 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of metal oxide semiconductor field effect transistors 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode522- longest special sequence ii- hash table - String - double pointer
Daily question -leetcode1175- permutation of prime numbers - Mathematics
TypeORM 框架
Unity项目心得总结
Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
Unity drags and modifies scene camera parameters under the editor
Copy baby prompt: material cannot be empty. How to solve it?
如何选择导电滑环材料
C WPF uses dockpanel to realize screenshot box
What things you didn't understand when you were a child and didn't understand until you grew up?
导电滑环短路的原因以及应对措施
eBPF Cilium实战(2) - 底层网络可观测性
Mathematical knowledge: finding the number of divisors
Printk debugging summary
实战:redux的基本使用
Simple read / write verification of qdatastream
Global and Chinese markets of superconductor 2022-2028: Research Report on technology, participants, trends, market size and share
0xc000007b应用程序无法正常启动解决方案(亲测有效)