Last active
August 29, 2015 13:57
-
-
Save lemnis/9697369 to your computer and use it in GitHub Desktop.
This file contains 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
<svg xmlns="http://www.w3.org/2000/svg" style="background:lightgrey"> | |
<text x="50%" y="50%" text-anchor="middle" style="font-family: sans-serif" > | |
<tspan id="asp" x="50%" dy="-20">Aspect-ratio</tspan> | |
<tspan id="dim" x="50%" dy="20">Dimensions</tspan> | |
</text> | |
<script type="text/ecmascript"> | |
<![CDATA[ | |
calc(); | |
window.onresize = function(){ | |
calc(); | |
} | |
function getAspectRatio(w, h){ | |
var rem; | |
var newW = w; | |
var newH = h; | |
while (h != 0){ | |
rem = w % h; | |
w = h; | |
h = rem; | |
} | |
return newW / w + ":" + newH / w; | |
} | |
function calc(){ | |
var rect = document.getElementsByTagName("svg")[0].getBoundingClientRect(); | |
document.getElementById("dim").innerHTML = rect.width +"px x "+ rect.height +"px"; | |
document.getElementById("asp").innerHTML = getAspectRatio(rect.width, rect.height) | |
} | |
]]> | |
</script> | |
</svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment