Skip to content

Instantly share code, notes, and snippets.

@justenh
Last active August 29, 2015 14:01
Show Gist options
  • Save justenh/2dd76232db5cce0ff3d4 to your computer and use it in GitHub Desktop.
Save justenh/2dd76232db5cce0ff3d4 to your computer and use it in GitHub Desktop.
JS scale to fit/fill
/**
*
*/
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);
}
@justenh
Copy link
Author

justenh commented May 15, 2014

Quick functions for scaling a width/height to fit or fill based on a min/max width/height.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment