Skip to content

Instantly share code, notes, and snippets.

@viclm
Last active August 28, 2021 19:41
Show Gist options
  • Save viclm/1de60f42e3029af08f4182a615f97462 to your computer and use it in GitHub Desktop.
Save viclm/1de60f42e3029af08f4182a615f97462 to your computer and use it in GitHub Desktop.
(function () {
var scale = 1 / window.devicePixelRatio;
document.querySelector('meta[name=viewport]').setAttribute('content', 'width=device-width,initial-scale='+scale+',maximum-scale='+scale+',minimum-scale='+scale+',user-scalable=no');
var rangingRem = document.createElement('div');
rangingRem.style.cssText = 'width:1rem;';
document.head.appendChild(rangingRem);
var defaultFontSize = parseFloat(getComputedStyle(rangingRem).getPropertyValue('width'), 10);
document.head.removeChild(rangingRem);
var uiWidth = parseInt(document.querySelector('meta[itemprop=uw]').getAttribute('content'), 10);
document.documentElement.style.fontSize = document.documentElement.clientWidth * 100 / uiWidth / defaultFontSize * 100 + '%';
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment