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?
PHP中文网
PHP中文网 2017-05-16 13:44:41
0
2
476
(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中文网

认证高级PHP讲师

reply all(2)
淡淡烟草味

Consider placing this js before the body tag

为情所困

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template