我不能得到<li>附加到我的元素$('ul#posts')淡入.
我试过的事情.
在淡入之前设置display:noneof <li>.在请求之后无法查看附加的html.这意味着fadeIn()没有用.
$(wall_post).appendTo('ul#posts').fadeIn("slow"); 似乎也没有用.
码:
var wall_post = '<li> <img src="image/avatar.jpg" class="avatar"><div class="status"><h2><a href="#" target="_blank">disran</a></h2><p class="message">' + textarea_content + '</p> ' + image_html + '<div class="data"><p class="name"><a href="' + siteurl + '" target="_blank">' + sitetitle + '</a></p><p class="caption">' + siteurl + '</p><p class="description">' + sitedesc + '</p></div></div> </div><p class="likes">5 hours ago · 100 Likes </p></li>';
var message_wall = $('#message_wall').attr('value');
$.ajax({
type: "GET",
url: "insert.php",
data: "message_wall=" + wall_post,
success: function () {
//$('ul#posts').append(wall_post).fadeIn('slow');
//$(wall_post).appendTo('ul#posts').fadeIn("slow");
$('ul#posts').append(wall_post).fadeIn('slow');
}
});
Run Code Online (Sandbox Code Playgroud)
wall_post HTML结构
<li>
<img src="image/avatar.jpg" class="avatar">
<div class="status">
<h2><a href="#" target="_blank">disran</a></h2>
<p class="message">[.. textarea_content ..]</p>
[.. image_html ..]
<div class="data">
<p class="name">
<a href="[.. siteurl ..]" target="_blank">[.. sitetitle ..]</a>
</p>
<p class="caption">[.. siteurl ..]</p>
<p class="description">[.. sitedesc ..]</p>
</div>
</div>
<p class="likes">5 hours ago 100 Likes</p>
</li>
Run Code Online (Sandbox Code Playgroud)
你现在正在使用一个字符串来处理,总是工作..所以我应该做的是使它成为这样的对象:
var wall_post = $('<li>[.. rest of html structure ..]</li>');
var message_wall = $('#message_wall').attr('value');
$.ajax({
type: "GET",
url: "insert.php",
// why are you sending the wallpost?? why getting you HTML from PHP??
// but i think its the message_wall variable you ment?
data: "message_wall=" + wall_post,
success: function () {
$('ul#posts').append(wall_post)
wall_post.hide(); // instant hide the wall_post
wall_post.fadeIn('slow'); // let is fadein slow
}
});
Run Code Online (Sandbox Code Playgroud)