最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to fade in appended HTML with jQuery? - Stack Overflow

programmeradmin3浏览0评论

I have the following line of code:

var html = "...";
$("#id_name").append(html).fadeIn("slow");

This causes the entire div #id_name to fade in. I want only the appended HTML to fade in. How can this be accomplished?

I have the following line of code:

var html = "...";
$("#id_name").append(html).fadeIn("slow");

This causes the entire div #id_name to fade in. I want only the appended HTML to fade in. How can this be accomplished?

Share Improve this question edited Aug 11, 2009 at 19:15 VolkerK 96.2k20 gold badges167 silver badges231 bronze badges asked Aug 11, 2009 at 19:14 jackjack
Add a comment  | 

3 Answers 3

Reset to default 17

You could do something like:

$('<div></div>').appendTo("#id_name").hide().append(html).fadeIn('slow');

you'd have to make sure the variable "html" is a jquery object first , and present in the DOM.

So you'd typically fire a callback function, fired when the append() is effective.

example:

$("#id_name").append(html,function(){
 $(html).fadeIn("slow");
});

This should also work (assuming the html var is a snippet of html code) and may be a bit more readable:

$(html).appendTo('#id_name').hide().fadeIn('slow');
发布评论

评论列表(0)

  1. 暂无评论