Javascript CSS缩放,然后调整为原始大小
我正在创建一个带有div和overflow:scroll的“缩放”效果。这是我的难题: 我使用以下方法: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
$('#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
。如果答案对你有帮助,不要忘记接受:)