移动端自动适配

//页面单位适配
(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var oBodyHeight = docEl.offsetHeight;
            var clientWidth = docEl.clientWidth;
            if(!clientWidth) return;
            if(clientWidth >= 750) clientWidth = 750;
            if(clientWidth <= 320) clientWidth = 320;
            docEl.style.fontSize = 625 * (clientWidth / 750) + '%';
            document.getElementsByTagName('body')[0].style.height = oBodyHeight+'px';
        };
    if(!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

说明:设计图为750px宽度;1rem=100px;例如设计图宽80,css写 0.8rem或者.8rem;

另附美女一幅,嘻嘻!

 

posted @ 2016-11-01 17:10  Xpress  阅读(236)  评论(0编辑  收藏  举报