开发者

How to use fade in jquery for prepend?

I want to use fade in effect for my prepend function.

I have tried follow one but it is not开发者_如何学编程 working.

$('#iq').prepend('.....').fadeIn('slow')


Try the example below.

$('#test').prepend($('<div id="bob">Hi der</div>').fadeIn('slow'));

Live Demo

Since you are just fading in the elements you are prepending just do it within the prepend as you add them, this also has the benefit of not forcing you to hide them first.


prepend returns the elements in the object you call it on, not the new elements, so you're calling fadeIn on the elements you're pre-pending the new content to. Instead, you want prependTo, which is basically prepend the other way 'round. (See the docs for details.) Also, you need to hide the new elements before fading them in, so:

$('.......').prependTo('#iq').hide().fadeIn('slow');

Live example


The element needs to be hidden first:

$('#iq').hide().prepend('.....').fadeIn('slow');


Problem: You have many div created new with prepend Solution: Add first new div with display:none and a class after prepend call class to get visible.

$('#putin').prepend('<div id="test" class="5" style="display:none">test1</div>');
$('.5').slideDown('slow');

fiddle

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜