Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animate .prepend

Tags:

jquery

Rather than simply dumping the HTML into the page I want it to be animated, how can I change the jQuery below to either animate or slide down as the HTML is inserted?

$('.button').click(function() {

j('.tweets ul').prepend(j('.refreshMe ul').html());

});
like image 997
CLiown Avatar asked Aug 26 '10 20:08

CLiown


People also ask

Is jQuery used for animation?

With jQuery, you can create custom animations.

Can the animate () method be used to animate any CSS property?

The animate() method is typically used to animate numeric CSS properties, for example, width , height , margin , padding , opacity , top , left , etc. but the non-numeric properties such as color or background-color cannot be animated using the basic jQuery functionality. Note: Not all CSS properties are animatable.

What does an easing do jQuery?

An easing function specifies the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called swing , and one that progresses at a constant pace, called linear .


1 Answers

You can .hide() the content before doing a .prependTo(), then call .slideDown() on the element, like this:

$('.button').click(function() {
 j('.refreshMe ul > *').clone().hide().prependTo('.tweets ul').slideDown();
});

This does .clone() of the children to move, rather than doing an innerHTML style copy, hides the cloned elements before moving them, then slides them down.

like image 140
Nick Craver Avatar answered Sep 18 '22 09:09

Nick Craver