当前位置:网站首页>Large screen: the display adaptation and font of the page on different scale screens change with the screen change (the font changes adaptively with the screen resolution)
Large screen: the display adaptation and font of the page on different scale screens change with the screen change (the font changes adaptively with the screen resolution)
2022-07-20 18:54:00 【Gegwu MMQ!!】
The page font is :rem
document.documentElement.style.fontSize = document.documentElement.clientWidth / 1280 + ‘px’; I am here. 1280 Is the screen size of the current self written page . The setting here is really html The reference dimension of is 1px;
Then in the style , use rem Set the font
At this point, the font can change with the screen size
But here's another problem : How about a square page , On a rectangular flat screen, it is displayed in equal proportion : I will adopt the proportional method
1280 and 884 These are the screens I use for development at this time
That's about it .
Consider some components , such as echarts All fonts are based on px As the standard , At this point, you can write a method
Then call it in the component
There is a problem of switching back and forth between large and small screens in the development .
So there will be the need for font size adaptation
StoreFactory.tsx in
interface IContexxt {
state:any,
dispatch?:React.Dispatch | undefined
}
export const createStore =(reducer:(state:any,action:any)=>object,defaultState:object,dispatchAction:any) =>{
const Context = React.createContext({state:defaultState});
const useAction = () =>{
const {dispatch} = useContext(Context);
return dispatchAction(dispatch);
}
}
return {useAction};
appStore.ts in
import {createStore} from ‘./storeFactory’;
import {appReducer,defaultState} from ‘./reduce’;
import {dispatchAction} from ‘./action’;
const {useAction,withStore,useStore} = createStore(appReducer,defaultState,dispatchAction);
export {withStore,useStore as useAppStore,useAction as useAppAction};
App.tsx in
const UIWidth = 1920 // Design width
const RootFontSizeRate = 100 // rem px Conversion ratio
const App: React.FC = () =>{
const action = useAppAction();
useEffect(()=>{
setRootFontsize();
window.onresize =() ={
setRootFontSize()
}
return ()={
widow.onresize = null;
}
},[])
}
const setRootFontSize = ()=>{
const {clientWidth} = document.documentElement;
const rootFontSize = clientWidth/UIWidth* RootFontSizeRate;
document.documentElement.style.fontsize = ${rootFontSize}px
action.setRootFontSize(rootFontSize);
边栏推荐
猜你喜欢
Pycharm Debug错误“Process finished with exit code -1073741819 (0xC0000005)”解决方案
从门户时代到信息流时代,好内容反而被忽略了?
Matlab实现热带气旋不同风期的风速转换
Solution to the problem of garbled code in visual code terminal
精挑细选的100道软测高频面试题,面试前你肯定用得上
19年大专毕业——认清生活的真相后,我选择了软件测试
性能提升30倍丨基于 DolphinDB 的 mytt 指标库实现
关于Visual Code终端乱码问题的解决方案
Browser view MD file strongly recommends markdown viewer
食腐秃鹫还是啄木鸟?如何正确理解做空
随机推荐
MATLAB绘制环形比例图
Implementation scheme of importing thinkphp6 million xlsx tables into the database
Draw 95% confidence interval diagram with MATLAB
若依框架-表单按照字段合计,按照某个字段排序
蔚小理,从难兄难弟到互相嫌弃
SQL中方括号的用途
软件测试岗——面试时三大灵魂拷问,你受得住吗?
R语言“Error in nls 循环次数超过了50”解决方案
Matlab实现热带气旋不同风期的风速转换
电子协会 C语言 2级 60 、整数奇偶排序(2021年 6月真题)
Netease game Flink SQL platform practice
为 KubeSphere 集群启用免费的泛域名 SSL 证书并实现证书自动更新和分发
Arcpy batch conversion data projection (taking Albers as an example)
Solution of webdriver click login failure
Dart final 和 const 变量
【terminal】x86 Native Tools Command Prompt for VS 2017
从门户时代到信息流时代,好内容反而被忽略了?
测试岗成功有没有捷径,我告诉你,唯一的捷径就是不走弯路
Software testing post - can you stand the torture of the three souls during the interview?
盒马“腰斩”,都怪侯毅话多?