I’m creating a “zoom” effect with a div with overflow:scroll. Here’s my dillema:
I use the following:
$('#object').css({ 'transform':'scale(50)' });
Which works beautifully, but now I would like to mathematically resize the element to it’s original width/height (keeping the scale at 50%, or whatever the value might be…)
$('#object').css({ 'width': ?+'px', 'height': ?+'px' });
Pretty sure this is a math issue, I can get close with the following:
new_width = parseInt(origWidth) + parseInt(Math.round(origWidth*((100-zoomScale)/100)));
new_height = parseInt(origHeight) + parseInt(Math.round(origHeight*((100-zoomScale)/100)));
Any help would be appreciated!
Your math is wrong.
But… if
700represent50%, then100%will be1400and not 700 + 350…So:
supose my vars are that the math to get the oposite keep zoom will be:
The math formula will be:
For the original values, you can use the
csswidthorheightthey will still the pixel original value, the modified by zoom value will be the clientWidth, clientHeight, offsetWidth and offsetHeight element properties.