Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Created June 21, 2014 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jongacnik/5187382bee80bd53cc87 to your computer and use it in GitHub Desktop.
Save jongacnik/5187382bee80bd53cc87 to your computer and use it in GitHub Desktop.
Aspect Ratio Helpers
// assumes jQuery or applicable DOM library
function getAspectByEle(ele){
var width = ele.width();
var height = ele.height();
return getAspectByVal(width,height);
}
function getAspectByEleAttr(ele){
var width = ele.attr('width');
var height = ele.attr('height');
return getAspectByVal(width,height);
}
function getAspectByVal(width,height){
return height/width;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment