如何动画宽度和计算新的左位置在同一时间与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()函数是这么说的;)
因此我需要在动画期间设置新的outerWidth(true)来计算新的位置
解决方案吗?
我认为你可以在动画中使用自定义的"step"函数来计算左边的位置。如下所示:http://api.jquery.com/animate/.
相关文章:
- jquery试图按名称获取按钮位置
- jQuery循环在特定位置暂停
- 使用jQuery更改元素的顶部位置
- jquery:将动画绑定到滚动条位置的更好方法
- JQuery幻灯片,可点击编号位置
- jQuery-仅更改Y轴的CSS背景位置
- Jquery Draggable-在浏览器刷新时保持位置
- 防止用户在jQuery Mobile中ajax加载页面时单击其他位置
- 我可以't使用jQuery更改工具提示引导程序的位置
- 我想滚动放大和缩小一个图像,但也有针在该图像上保持正确的位置.jQuery
- 获取元素内文本的初始和最终位置?- jQuery.
- 返回上一个滚动位置 - jquery移动页面设计
- 固定位置Jquery上的Easing
- 鼠标释放时抓取元素的位置jQuery可拖动
- 当单击按钮时,转到html页面的下一个位置- jquery
- 相对于当前位置 Jquery 滚动
- 位置jQuery对话框
- 设置窗口的位置/jquery
- 将同一字段的错误消息放在不同的位置 jquery 中
- 的位置.jquery事件中没有重定向