Development

Fix jQuery’s animate() to allow “auto” values

Posted Jan 14 2011

Going through the jQuery source you start to learn how things are processed by the library. A few months ago I noticed that the .animate() method wasn’t able to compute “auto” values for elements and animate accordingly. After Google-ing the issue I noticed that it’s a big issue for some people. This past month I put together a fix that I hope to add to the core through a pull request later this month to rectify this issue.

For now, you can temporarily use the fix as my example below shows. The main idea is to clone the element and place it before itself while changing its CSS properties to “auto” and ultimately finding the “px” native value of said element. Take a look:

5 Comments

Tomasz Szawara Posted: Jun 13, 2011 @ 2:26pm

Hi Darcy, You can just use position() method in order to get (left & top) even if they have auto values. It will return their position relative to nearest relatively positioned element ;-)

NemoStein Posted: Sep 13, 2011 @ 8:58pm

Love you man… Works like a charm! BTW, why isn’t it in the jquery core yet?

Nick Posted: Dec 05, 2011 @ 2:32am

@Tomasz Szawara, what you said isn’t what he’s talking about, read this page again, because you misunderstood.

I’ve been trying to figure out how to do this for awhile, thank you so much!

[...] อันนี้มาจาก Fix jQuery’s animate() to allow “auto” values” ของ [Darcy Clarke]http://darcyclarke.me/) ครับ เนื่องจากว่า [...]

Adrian Adkison Posted: Feb 27, 2012 @ 10:56pm

If whatever content you clone has a radio button inside it, it will cause the radio button to become unchecked.

Leave a Reply: