Home >Web Front-end >JS Tutorial >Detailed introduction to the example code of rem adaptation
Detailed introduction to the example code of rem adaptation
; (function(win) { var doc = win.document; var docEl = doc.documentElement; var tid; function refreshRem() { var width = docEl.getBoundingClientRect().width; if (width > 540) { // 最大宽度 width = 540; } var rem = width / 6.4; docEl.style.fontSize = rem + 'px'; } win.addEventListener('resize', function() { clearTimeout(tid); tid = setTimeout(refreshRem, 300); }, false); win.addEventListener('pageshow', function(e) { if (e.persisted) { clearTimeout(tid); tid = setTimeout(refreshRem, 300); } }, false); refreshRem(); })(window);
Set the font under 680 original manuscript to 100px, this is to facilitate calculation
The above is the detailed content of Detailed introduction to the example code of rem adaptation. For more information, please follow other related articles on the PHP Chinese website!