-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflexible.mini.js
3 lines (3 loc) · 1.4 KB
/
flexible.mini.js
1
2
3
(function(d,b){function g(){h=l.getBoundingClientRect().width;540<h/a&&(h=540*a);m=h/10;l.style.fontSize=m+"px";f.rem=d.rem=m}var n=this,e=d.document,l=e.documentElement,c=e.querySelector('meta[name="viewport"]'),p=c&&c.getAttribute("content").match(/initial\-scale=([\d\.]+)/),q=d.devicePixelRatio,r=d.navigator.appVersion.match(/iphone/gi),f=b.flexible||(b.flexible={}),h=void 0,a=b=0,k=void 0,m=void 0;c&&(console.info("\u6587\u6863\u4e2d\u5df2\u7ecf\u8bbe\u7f6e\u4e86viewport\uff0c\u5c06\u6839\u636e\u5df2\u6709\u7684\u53c2\u6570\u8bbe\u7f6e\u7f29\u653e\u6bd4\u4f8b"),
p&&(b=p[1],a=parseInt(1/b)));a||b||(a=r?3<=q&&(!a||3<=a)?3:2<=q&&(!a||2<=a)?2:1:1,b=1/a);l.setAttribute("data-dpr",a);c||(c=e.createElement("meta"),c.setAttribute("name","viewport"),c.setAttribute("content","initial-scale="+b+", maximum-scale="+b+", minimum-scale="+b+", user-scalable=no"),e.head.appendChild(c));g();d.addEventListener("resize",function(){clearTimeout(k);k=setTimeout(g,300)},!1);d.addEventListener("pageshow",function(a){a.persisted&&(clearTimeout(k),k=setTimeout(g,300))},!1);e.addEventListener("DOMContentLoaded",
function(){e.body.style.fontSize=12*a+"px"},!1);f.dpr=d.dpr=a;f.refreshRem=g;f.rem2px=function(a){var b=parseFloat(a)*n.rem;"string"===typeof a&&a.match(/rem$/)&&(b+="px");return b};f.px2rem=function(a){var b=parseFloat(a)/n.rem;"string"===typeof a&&a.match(/px$/)&&(b+="rem");return b}})(window,window.lib||(window.lib={}));