search

Home  >  Q&A  >  body text

javascript - The mobile terminal introduces js to control the font-size of the root element, but there will be jitter when the page is initialized. Are there any other optimization methods?

(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var clientWidth = docEl.clientWidth;
            if(!clientWidth) return;
            docEl.style.fontSize = (clientWidth >= 720 ? 100 : clientWidth / 7.5) + 'px';
        };
    if(!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
PHP中文网PHP中文网2774 days ago515

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 13:46:41

    Consider placing this js before the body tag

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:46:41

    There is a compromise solution. First, set the display of the body: none;
    Then use js to control the timing. After 1 millisecond, the display of the body is block;

    setTimeout(showpage,1);

    function showpage(){
        $('body').css({'display':'block','visibility':'visible'})
    }

    The disadvantage is that when loading, there will be a white screen for one millisecond without jitter. 1 millisecond is considered very short. If you don’t mind, you can try it.

    reply
    0
  • Cancelreply