【发布时间】:2011-08-21 14:37:42
【问题描述】:
我对 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() 函数是这样说的;)
因此我需要在动画期间使用新的 outerWidth(true) 来计算新的位置。
有什么解决办法吗?
【问题讨论】:
标签: javascript jquery jquery-animate