Skip to content

Instantly share code, notes, and snippets.

@SauloSilva
Created November 12, 2013 16:38
Show Gist options
  • Save SauloSilva/7434170 to your computer and use it in GitHub Desktop.
Save SauloSilva/7434170 to your computer and use it in GitHub Desktop.
scale element
window.scaler = function(options) {
var a, ab, b, c, cd, d, e, f, scale;
a = options.srcWidth;
b = options.srcHeight;
c = options.windowWidth;
d = options.windowHeight;
console.log(c, d);
ab = a / b;
cd = c / b;
e = 0;
f = 0;
if (ab > cd) {
e = c;
f = c * b / a;
} else {
e = a * d / b;
f = d;
}
return scale = {
width: e,
height: f
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment