/** * rem计算方式:设计图尺寸px / 100 = 实际rem 例: 100px = 1rem */ !function (window) { /* 设计图文档宽度 */ var docwidth = 750; var doc = window.document, docel = doc.documentelement, resizeevt = 'orientationchange' in window ? 'orientationchange' : 'resize'; var recalc = (function refreshrem () { var clientwidth = docel.getboundingclientrect().width; /* 8.55:小于320px不再缩小,20:大于750px不再放大 */ docel.style.fontsize = math.max(math.min(20 * (clientwidth / docwidth), 20), 8.55) * 5 + 'px'; return refreshrem; })(); /* 添加倍屏标识,安卓倍屏为1 */ docel.setattribute('data-dpr', window.navigator.appversion.match(/iphone/gi) ? window.devicepixelratio : 1); if (/ip(hone|od|ad)/.test(window.navigator.useragent)) { /* 添加ios标识 */ doc.documentelement.classlist.add('ios'); /* ios8以上给html添加hairline样式,以便特殊处理 */ //if (parseint(window.navigator.appversion.match(/os (\d+)_(\d+)_?(\d+)?/)[1], 10) >= 8) //doc.documentelement.classlist.add('hairline'); } if (!doc.addeventlistener) return; window.addeventlistener(resizeevt, recalc, false); doc.addeventlistener('domcontentloaded', recalc, false); }(window);