繁体   English   中英

如何使用jQuery设置宽度的动画并同时计算新的左侧位置?

[英]How to animate the width and calculate the new left position at the same time with jQuery?

我在jQuery中的animate()函数有问题:

$(this).addClass(activeClass).animate({
  position: 'absolute'
  width: '200%',

//Here is the problem. I need the new outerWidth(true) 
//(Width+Padding+Margin+Border) of the animated element to calculate 
//the new position. I want it to be centered from it's old position. 
//But it is still using the current outerWidth.

  left : -($(this).outerWidth(true)-defaultOuterWidth)/2

});

例:

假设我有一个div,我想将其大小调整为200%。 div开头的边距为20px,宽度为200px。

应用了“ activeClass”之后,可能是页边距现在为40px宽,它现在具有边框和400px的新宽度,因为animate()函数表示为;)

因此,在动画处理期间我需要新的externalWidth(true)来计算新位置。

有什么办法吗?

我认为您可以对动画使用自定义的“步进”功能,以自己计算左侧位置。 在此处进行了描述: http : //api.jquery.com/animate/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM