Created
July 29, 2019 08:24
-
-
Save dsdsdsdsdsds/ac2f275c6bad37de05a426198be0fd34 to your computer and use it in GitHub Desktop.
Scale element to be always contained within container
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 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