You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
1.8 KiB

4 weeks ago
(function(r,p){var a=r.document,o=a.documentElement,l=a.querySelector('meta[name="viewport"]'),c=a.querySelector('meta[name="flexible"]'),e=0,i=0,m,s=p.flexible||(p.flexible={});if(l){console.warn("将根据已有的meta标签来设置缩放比例");var v=l.getAttribute("content").match(/initial\-scale=([\d\.]+)/);v&&(i=parseFloat(v[1]),e=parseInt(1/i))}else if(c){var d=c.getAttribute("content");if(d){var u=d.match(/initial\-dpr=([\d\.]+)/),h=d.match(/maximum\-dpr=([\d\.]+)/);u&&(e=parseFloat(u[1]),i=parseFloat((1/e).toFixed(2))),h&&(e=parseFloat(h[1]),i=parseFloat((1/e).toFixed(2)))}}if(!e&&!i){r.navigator.appVersion.match(/android/gi);var g=r.navigator.appVersion.match(/iphone/gi),x=r.devicePixelRatio;g?x>=3&&(!e||e>=3)?e=3:x>=2&&(!e||e>=2)?e=2:e=1:e=1,i=1/e}if(o.setAttribute("data-dpr",e),!l)if(l=a.createElement("meta"),l.setAttribute("name","viewport"),l.setAttribute("content","initial-scale="+i+", maximum-scale="+i+", minimum-scale="+i+", user-scalable=no"),o.firstElementChild)o.firstElementChild.appendChild(l);else{var b=a.createElement("div");b.appendChild(l),a.write(b.innerHTML)}function f(){var t=o.getBoundingClientRect().width;t/e>540&&(t=540*e);var n=t/10;o.style.fontSize=n+"px",s.rem=r.rem=n}r.addEventListener("resize",function(){clearTimeout(m),m=setTimeout(f,300)},!1),r.addEventListener("pageshow",function(t){t.persisted&&(clearTimeout(m),m=setTimeout(f,300))},!1),a.readyState==="complete"?a.body.style.fontSize=12*e+"px":a.addEventListener("DOMContentLoaded",function(t){a.body.style.fontSize=12*e+"px"},!1),f(),s.dpr=r.dpr=e,s.refreshRem=f,s.rem2px=function(t){var n=parseFloat(t)*this.rem;return typeof t=="string"&&t.match(/rem$/)&&(n+="px"),n},s.px2rem=function(t){var n=parseFloat(t)/this.rem;return typeof t=="string"&&t.match(/px$/)&&(n+="rem"),n}})(window,window.lib||(window.lib={}));