js code layout adaptive rem

In front of the head inside with this sentence prohibits Zoom:
 
 <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
 
The following is the code that the code js 1rem = 100px:
 
!(function(win, doc) {
    function setFontSize() {
        var winWidth = window.innerWidth;
        doc.documentElement.style.fontSize = (winWidth / 1080) * 100 + 'px';
    }
    var evt = 'onorientationchange' in win ? 'orientationchange' : 'resize';
    were hours = null;
    win.addEventListener(evt, function() {
        clearTimeout(timer);
        timer = setTimeout(setFontSize, 300);
    }, false);
    win.addEventListener("pageshow", function(e) {
        if (e.persisted) {
            clearTimeout(timer);
            timer = setTimeout(setFontSize, 300);
        }
    }, false);
    //initialization 
    setFontSize();
}(window, document));

Guess you like

Origin www.cnblogs.com/an2333/p/11608487.html