Last active
August 29, 2015 14:01
-
-
Save justenh/2dd76232db5cce0ff3d4 to your computer and use it in GitHub Desktop.
JS scale to fit/fill
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
/** | |
* | |
*/ | |
function getScaleTofit(width, height, maxWidth, maxHeight) | |
{ | |
return Math.min(maxWidth / width, maxHeight / height); | |
} | |
/** | |
* | |
*/ | |
function getScaleToFill(width, height, minWidth, minHeight) | |
{ | |
return Math.max(maxWidth / width, maxHeight / height); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick functions for scaling a width/height to fit or fill based on a min/max width/height.