Created
November 25, 2015 07:52
-
-
Save ariona/58582e7aa937b5e9c9d0 to your computer and use it in GitHub Desktop.
Proportionally Scale Any HTML Content
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
var $el = $("#very-specific-design"); | |
var elHeight = $el.outerHeight(); | |
var elWidth = $el.outerWidth(); | |
var $wrapper = $("#scaleable-wrapper"); | |
$wrapper.resizable({ | |
resize: doResize | |
}); | |
function doResize(event, ui) { | |
var scale, origin; | |
scale = Math.min( | |
ui.size.width / elWidth, | |
ui.size.height / elHeight | |
); | |
$el.css({ | |
transform: "translate(-50%, -50%) " + "scale(" + scale + ")" | |
}); | |
} | |
var starterData = { | |
size: { | |
width: $wrapper.width(), | |
height: $wrapper.height() | |
} | |
} | |
doResize(null, starterData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment