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:

tags: / / / / /

5 comments

  • Tomasz Szawara

    Posted: Jun 13, 2011

    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

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

  • Nick

    Posted: Dec 5, 2011

    @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!

  • Animate height/width to “auto” | phato.blog`

    Posted: Jan 12, 2012

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

  • Adrian Adkison

    Posted: Feb 27, 2012

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

"w3fools.com - because friends don't let friends use w3schools" ~ dan heberden
themify
Learning JavaScript