0

li附加到列表后,我在某些元素中淡化时遇到了一些麻烦。

var html 包含列表项。

$(html).hide().appendTo('#thelist').fadeIn();

当加载了单个 li 元素时,淡入起作用,但是如果有多个 li 的 jQuery 没有插入任何东西,更不用说淡入了。

有人可以建议修复吗?

编辑1:

示例 - thelist 是我的 ul,它没有隐藏。

<ul id="thelist">
   <li>entry1</li>
   <li>entry2</li>
   <li>entry3</li>
</ul>

编辑 2:该列表存在于 HTML 中,然后 jQuery 添加了我希望淡入的其他 li。

编辑 3: html 包含一个 jQuery ajax 调用,其中包含 html 以显示大约 5 li 的文章内容。当我不使用淡入或动画时,它会正确添加到 ul 中。当我添加淡入淡出时,它会将元素添加到 ul 但它不会淡入淡出。

编辑4:这是加载功能:

 $(function() {
     $('.more').live('click',function() {
     var element = $(this);
     var msg = element.attr('id');
     $('#morebutton').html('<p><em>Loading Articles.</em></p>');
     $.ajax({
         type: 'POST',
         url: 'more.asp',
         data: 'lastmsg=' + msg,
         cache: false,
         success: function(html){
             $('#morebutton').remove();
             $(html).hide().appendTo('#thelist').fadeIn();
         }
     });
     });
 });

解决方案:

我通过改变让它淡入:

 $(html).hide().appendTo('#thelist').fadeIn();

 var item = $(html).fadeIn();
 $('#thelist').append(item);

似乎这与 jQuery 以特定顺序链接的方式有关。

4

3 回答 3

0

尝试使用后

$(html).hide().after('#thelist').fadeIn();
于 2012-01-24T02:03:44.000 回答
0

这对我来说很好。确保您的列表项和列表存在。检查任何 id 的拼写错误。

http://jsfiddle.net/gftdz/1/

于 2012-01-24T02:17:40.193 回答
0

不确定,但可能你想要这样的东西

$('#thelist').fadeOut('fast',function(){$('#thelist').append(html).fadeIn()});
于 2012-01-24T02:57:06.590 回答