Skip to content

Instantly share code, notes, and snippets.

@dsdsdsdsdsds
Created July 29, 2019 08:24
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 dsdsdsdsdsds/ac2f275c6bad37de05a426198be0fd34 to your computer and use it in GitHub Desktop.
Save dsdsdsdsdsds/ac2f275c6bad37de05a426198be0fd34 to your computer and use it in GitHub Desktop.
Scale element to be always contained within container
function contain(element, container) {
const scale = Math.min(
container.offsetWidth / element.offsetWidth,
container.offsetHeight / element.offsetHeight
)
return scale
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment