Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

大佬,想请教一个问题 #2

Open
fatpiginhome opened this issue Oct 9, 2019 · 3 comments
Open

大佬,想请教一个问题 #2

fatpiginhome opened this issue Oct 9, 2019 · 3 comments

Comments

@fatpiginhome
Copy link

在你写的rem布局中,为什么要设置calcMaxWidth = 9999999,还有clientWidth为什么要进行Math.max和Math.min操作呢,直接取html的clientWidth不行吗

@imwtr
Copy link
Owner

imwtr commented Oct 9, 2019

在你写的rem布局中,为什么要设置calcMaxWidth = 9999999,还有clientWidth为什么要进行Math.max和Math.min操作呢,直接取html的clientWidth不行吗

可以看一下这里REM的解析

@imwtr
Copy link
Owner

imwtr commented Oct 9, 2019

是为了控制页面能有个最大和最小的宽度,不至于被压缩得错乱,或拉伸得很长。
calcMaxWidth 只是一个参考值,设置很大用以取这个“最大宽度”

if (metaElem.getAttribute('data-content-max') !== null) {
        calcMaxWidth = defaultMaxWidth;
    }

meta标签上面的data-content-max属性表示需要开启这个宽度限制的特性,开启了才会限制最大宽度的,不设最小宽度,小的时候肯定会挤得不成样子,所以默认是限制了最小

clientWidth = Math.max(clientWidth, defaultMinWidth * dpr)

@fatpiginhome
Copy link
Author

说的很好,受教了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants