2

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!

asked Dec 20, 2011 at 15:31

1 Answer 1

3

Your math is wrong.

700 * 0.5 = 350

But... if 700 represent 50%, then 100% will be 1400 and not 700 + 350...

So:

700 * 2 = 1400

supose my vars are that the math to get the oposite keep zoom will be:

(1/0.5) * 700

The math formula will be:

(1/(zoomScale/100)) * originalValue

For the original values, you can use the css width or height they will still the pixel original value, the modified by zoom value will be the clientWidth, clientHeight, offsetWidth and offsetHeight element properties.

answered Dec 20, 2011 at 16:42
Sign up to request clarification or add additional context in comments.

2 Comments

That works well, thanks. Now, what if I want to upsize, let's say 150%?
(1/zoomScale/100))*originalValue where 1 is your scale factor, to 150%, change 1 to 1.5. Don't forgot to accept the answer if it help you :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.