大前端高工 2021-09-18 22:34:18 阅读数:612
1rem = 1 * htmlFontSize
@media screen and (min-width: 640px) {html{font-size:100px;}}
window.innerWidth / designWidth * rem2px + ‘px’
defaultFontSize = 16px
1rem = 1 * htmlFontSize * defaultFontSize
@media screen and (min-width: 640px) {html{font-size:625%;}}
1rem = 1 * 625% * 16px
其中:625% * 16 = 6.25 * 16 = 100
所以:1rem = 1 * 100px
window.innerWidth / designWidth * rem2px / 16 * 100 + ‘%’
document.documentElement.style.fontSize = 56.25px
htmlFontSize = 56.25px
1rem = 1 * htmlFontSize = 56.25px
實際為:
1rem = 64.6875px
document.documentElement.style.fontSize = 351.5625%
htmlFontSize = 351.5625%
defaultFontSize = 18px
1rem = 1 * htmlFontSize * defaultFontSize = 351.5625% * 18px = 63.28125px
351.5625% * 18 = 63.28125
實際為:
1rem = 64.6875px
// 方案3
document.documentElement.style.fontSize =
window.innerWidth / designWidth * rem2px + ‘px’;
// 方案4
document.documentElement.style.fontSize =
window.innerWidth / designWidth * rem2px / 16 * 100 + ‘%’;
1rem = 1 * (56.25px / 16) * 18
1 * (56.25 / 16) * 18 = 63.28125
1rem = 1 * (htmlFontSize / 16) * defaultFontSize
var designWidth = 640, rem2px = 100;
var h = document.getElementsByTagName(‘html’)[0];
var htmlFontSize = parseFloat(window.getComputedStyle(h, null)
document.documentElement.style.fontSize =
window.innerWidth / designWidth * rem2px / htmlFontSize * 100 + ‘%’;
var designWidth = 640, rem2px = 100;
var d = window.document.createElement(‘div’);
d.style.width = ‘1rem’;
d.style.display = “none”;
var head = window.document.getElementsByTagName(‘head’)[0];
head.appendChild(d);
為了幫助大家更好溫習重點知識、更高效的准備面試,特別整理了《前端工程師面試手册》電子稿文件。
內容包括html,css,JavaScript,ES6,計算機網絡,瀏覽器,工程化,模塊化,Node.js,框架,數據結構,性能優化,項目等等。
包含了騰訊、字節跳動、小米、阿裏、滴滴、美團、58、拼多多、360、新浪、搜狐等一線互聯網公司面試被問到的題目,涵蓋了初中級前端技術點。
前端面試題匯總
CodeChina開源項目:【大廠前端面試題解析+核心總結學習筆記+真實項目實戰+最新講解視頻】
JavaScript
性能
linux
版权声明:本文为[大前端高工]所创,转载请带上原文链接,感谢。 https://gsmany.com/2021/09/20210918223418190d.html