jQuery平滑地改变innerHTML

Jad*_*ias 9 html javascript jquery slideup

我有下面的代码像魅力:

var div = $('#div');
div.html('<div>one line</div><div>another line</div>');
div.slideDown('slow');
Run Code Online (Sandbox Code Playgroud)

但是当我需要更改内容(行数)时问题就出现了:

div.html('<div>one line replacement</div><div>another line replacement</div><div>third line</div>')
Run Code Online (Sandbox Code Playgroud)

这种转变太快了.如何动画这个?

Dan*_*oof 6

您可以在html中添加一个不可见的范围:

<span class="foo" style="display: none">some other lines</span>
Run Code Online (Sandbox Code Playgroud)

然后淡出它们:

$("span.foo").fadeIn('slow');
Run Code Online (Sandbox Code Playgroud)


通过编辑,您可能还需要考虑:

div.slideUp('slow'); // you may want this to be 'fast'
div.html('some other lines');
div.slideDown('slow');
Run Code Online (Sandbox Code Playgroud)