Created
January 11, 2017 09:18
-
-
Save flyfloor/b5e25c8b02aa665e15e23a2368ad6f91 to your computer and use it in GitHub Desktop.
responsive for mobile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){var UA=navigator.userAgent,isAndroid=/android|adr/gi.test(UA),isIos=/iphone|ipod|ipad/gi.test(UA)&&!isAndroid,isMobile=isAndroid||isIos;var docEl=document.documentElement,maxwidth=docEl.dataset.mw||750,dpr=isIos?Math.min(window.devicePixelRatio,3):1,scale=1/dpr,tid;docEl.removeAttribute("data-mw");docEl.dataset.dpr=dpr;metaEl=document.createElement("meta");metaEl.name="viewport";metaEl.content=fillScale(scale);docEl.firstElementChild.appendChild(metaEl);var refreshRem=function(){var width=docEl.getBoundingClientRect().width;if(width/dpr>maxwidth){width=maxwidth*dpr}var rem=width/16*2.2;docEl.style.fontSize=rem+"px"};window.addEventListener("resize",function(){clearTimeout(tid);tid=setTimeout(refreshRem,300)},false);window.addEventListener("pageshow",function(e){if(e.persisted){clearTimeout(tid);tid=setTimeout(refreshRem,300)}},false);function fillScale(scale){return"width=device-width,initial-scale="+scale+",maximum-scale="+scale+",minimum-scale="+scale}refreshRem()})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment