Is there a way to animate the change in width upon setting a text() of an element?
Say, we have
<a id="link" href="#">container/sub1/sub2</a>
that is then changed programmatically by, say, $('#link').text('sub2'); into this:
<a id="link" href="#">sub2</a>
Normally, said element’s width will change instantly, but the effect I’m looking for is its gradual animated reduction.
Thank you.
You could do something like this:
http://jsfiddle.net/HYZbA/
I have basically wrapped the
<a>in a div withoverflow:hidden. Then when the text is changed, the wrapper is animated to the size of thea.NOTE: The red border is just so you can see what’s happening. Remove this to see it in action.