Skip to content

Instantly share code, notes, and snippets.

@johnpmorris
Last active August 21, 2017 00:08
Show Gist options
  • Save johnpmorris/f40bc9ba67a0699c0846443152e1a2ba to your computer and use it in GitHub Desktop.
Save johnpmorris/f40bc9ba67a0699c0846443152e1a2ba to your computer and use it in GitHub Desktop.
get and display the aspect ratio of the browser window
(function(){ var wr; function gcd(a,b) {if(b>a) {temp = a; a = b; b = temp} while(b!=0) {m=a%b; a=b; b=m;} return a;} function r(x,y) {c=gcd(x,y); return ""+(x/c)+"/"+(y/c)} function setwr() { wr = r(window.innerWidth, window.innerHeight); var rd = document.createElement("div"); rd.id = 'rd'; rd.style.position = 'absolute'; rd.style.fontSize = '12px'; rd.style.backgroundColor = '#000'; rd.style.color = '#FFF'; rd.style.top = 0; rd.style.left = 0; var rt = document.createTextNode(wr); rd.appendChild(rt); document.body.appendChild(rd); } function updatewr(){ wr = r(window.innerWidth, window.innerHeight); document.querySelector('#rd').innerText = wr; } window.addEventListener('resize', updatewr); setwr(); })();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment