简体   繁体   English

jQuery 左右动画

[英]jQuery Animate with left and right

When using jQuery.animate(width: value) it animates the width from left to right.使用 jQuery.animate(width: value) 时,它会从左到右对宽度进行动画处理。 So if you have a 10px div and you want to animate the width to be 100px.所以如果你有一个 10px 的 div 并且你想将宽度设置为 100px。 It will animate for the left to the right making the div bigger.它将从左到右进行动画处理,使 div 更大。

What I need is it to animate both left and right evenly.我需要的是左右均匀地设置动画。 Perhaps my example will help.也许我的例子会有所帮助。

Example here: (Navigation at the top) http://www.search-this.com/examples/eberl-reboot/index2.html此处示例:(顶部导航) http://www.search-this.com/examples/eberl-reboot/index2.html

I want the animation to not just go left to right, but start in the middle and fill left and right.我希望 animation 不仅仅是 go 从左到右,而是从中间开始并左右填充。 Make sense?说得通?

There are probably other ways to explain this, perhaps some better, but do you get what I need?可能还有其他方法可以解释这一点,也许更好一些,但你得到我需要的了吗?

Thanks谢谢

Try this out, it should do what you want: http://jsfiddle.net/bZAsp/试试这个,它应该做你想做的: http://jsfiddle.net/bZAsp/

It does get a little funky if you spam the animate button, but that's an exercise left to the reader to fix:)如果您向动画按钮发送垃圾邮件,它确实会变得有点时髦,但这是留给读者修复的练习:)

You need to animate the left position as well, taking into account the delta change in width:您还需要为左侧 position 设置动画,同时考虑宽度的增量变化:

http://jsfiddle.net/ZfvBK/3/ http://jsfiddle.net/ZfvBK/3/

hope that helps希望有帮助

Try this.尝试这个。 But you have to calcualte these values dynamically based on how much width you want to animate.但是您必须根据要设置动画的宽度动态计算这些值。

$(someElement).animate({ "margin-left": "+=50", "width": 200});

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

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