rem問(wèn)題
var?docEl?=?document.documentElement, ????resizeEvt?=?'orientationchange'?in?window???'orientationchange'?:?'resize', ????recalc?=?function()?{ ????????//設(shè)置根字體大小 ????????docEl.style.fontSize?=?20?*?(docEl.clientWidth?/?320)?+?'px'; ????}; //綁定瀏覽器縮放與加載時(shí)間 window.addEventListener(resizeEvt,?recalc,?false); document.addEventListener('DOMContentLoaded',?recalc,?false);
這段是動(dòng)態(tài)獲取font-size大小嗎?假如clientWidth=320px,此時(shí)font-size=20px,1rem=20px,這時(shí)候20px是不是有點(diǎn)大啊?怎樣獲取最合適的font-size,就是比如div{width:400px;height=400px;border:1px solid}在不同clientWidth下讓這個(gè)盒子看起來(lái)大小最舒服?
2016-05-24
var?docEl?=?document.documentElement,
????resizeEvt?=?'orientationchange'?in?window???'orientationchange'?:?'resize',
????recalc?=?function()?{
????????//設(shè)置根字體大小
????????docEl.style.fontSize?=?16 *?(docEl.clientWidth?/?320)?+?'px';
????};