Skip to content

Instantly share code, notes, and snippets.

@namomo
Created October 28, 2015 01:46
Show Gist options
  • Save namomo/6ef39b80f64a81fad706 to your computer and use it in GitHub Desktop.
Save namomo/6ef39b80f64a81fad706 to your computer and use it in GitHub Desktop.
div resize
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