Created
October 28, 2015 01:46
-
-
Save namomo/6ef39b80f64a81fad706 to your computer and use it in GitHub Desktop.
div resize
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 resizeDiv() | |
{ | |
var size = { | |
width: window.innerWidth || document.body.clientWidth, | |
height: window.innerHeight || document.body.clientHeight | |
}; | |
var contSize = { | |
width: 480, | |
height: 720 | |
} | |
var box = document.getElementById('resizediv'); | |
var rate; | |
if (size.width < size.height) { | |
rate = size.width/contSize.width; | |
} | |
else { | |
rate = size.height/contSize.height; | |
} | |
var tx = (size.width-(contSize.width*rate))/2; | |
var ty = (size.height-(contSize.height*rate))/2; | |
box.style.left = tx+'px'; | |
box.style.top = ty+'px'; | |
box.style.transformOrigin = '0px 0px 0px'; | |
box.style.transform = 'scale('+rate+', '+rate+')'; | |
box.style.webkitTransformOrigin = '0px 0px 0px'; | |
box.style.webkitTransform = 'scale('+rate+', '+rate+')'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment