Javascript CSS缩放,然后调整为原始大小

Javascript CSS缩放,然后调整为原始大小,javascript,math,transform,scale,Javascript,Math,Transform,Scale,我正在创建一个带有div和overflow:scroll的“缩放”效果。这是我的难题: 我使用以下方法: $('#object').css({ 'transform':'scale(50)' }); new_width = parseInt(origWidth) + parseInt(Math.round(origWidth*((100-zoomScale)/100))); new_height = parseInt(origHeight) + parseInt(Math.round(orig

我正在创建一个带有div和overflow:scroll的“缩放”效果。这是我的难题:

我使用以下方法:

$('#object').css({ 'transform':'scale(50)' });
new_width = parseInt(origWidth) + parseInt(Math.round(origWidth*((100-zoomScale)/100)));
new_height = parseInt(origHeight) + parseInt(Math.round(origHeight*((100-zoomScale)/100)));
它工作得很好,但是现在我想用数学方法将元素调整为其原始宽度/高度(将比例保持在50%或任何值…)

非常确定这是一个数学问题,我可以接近以下内容:

$('#object').css({ 'transform':'scale(50)' });
new_width = parseInt(origWidth) + parseInt(Math.round(origWidth*((100-zoomScale)/100)));
new_height = parseInt(origHeight) + parseInt(Math.round(origHeight*((100-zoomScale)/100)));
任何帮助都将不胜感激

你的数学错了

700 * 0.5 = 350
但是。。。如果
700
代表
50%
,那么
100%
将是
1400
,而不是700+350

因此:

supose my vars认为获得oposite keep zoom的数学公式为:

(1/0.5) * 700
数学公式为:

(1/(zoomScale/100)) * originalValue

对于原始值,您可以使用
css
width
height
它们仍然是像素原始值,修改后的by zoom值将是clientWidth、clientHeight、offsetWidth和offsetHeight元素属性。

非常有效,谢谢。现在,如果我想放大,比如说150%?(
1
/zoomScale/100))*原始值,其中1是您的比例因子,将
1
更改为
1.5
。如果答案对你有帮助,不要忘记接受:)