如何动画jquery load()

您好我正在使用此代码从另一个PHP文件加载内容。

$(document).ready(function(){ setInterval(function(){ $('.live-stream ul').each(function(){ $(this).load('tx.php'); }); }, 1000); }); 

这工作正常,但我希望脚本淡入每个“li”时添加一个新记录,任何人?

我想要做的事情就像Facebook的家庭右侧顶部的facebook的实时用户动作源

你必须先隐藏它。

 $(this).hide().load("tx.php").fadeIn('500'); 

尝试这样的事情:

 $(document).ready(function(){ setInterval(function(){ $('.live-stream ul').each(function(){ $(this).hide().load('tx.php').fadeIn('500'); }); }, 1000); }); 

注意使用fadeIn()hide() ……如果已经隐藏了

  • 则不需要隐藏。

    如果你调用fadeIn方法怎么办?

     $(this).load('tx.php').fadeIn(400); 

    加载时调用处理程序

     $(document).ready(function(){ setInterval(function(){ $('.live-stream ul').each(function(){ $(this).load('tx.php', function(){ $('li').fadeIn("normal"); }); }); }, 1000); }); 

    你试过这个吗?

     $(document).ready(function(){ setInterval(function(){ $('.live-stream ul').each(function(){ $(this).load('tx.php').fadeIn('1000'); }); }, 1000); }); 

    嗯,这个怎么样

     $(function(){ //Fade in all objects. var wrapper = $("live-stream ul"); $(wrapper).hide(); function fadeInAll(elem, fadeInTime, timeBetween) { for(i=0; i 

    使用回调但使用CSS display: none;隐藏li display: none; fadeIn应该在那之后工作。

     $(document).ready(function(){ setInterval(function(){ $('.live-stream ul').each(function(){ $(this).load('tx.php', function(){ $(this).find('li').fadeIn(); }); }); }, 1000); }); 

    在执行.fadeIn(“1000”)之前显示$(this)。 首先,您必须隐藏所选元素,加载内容然后fadeIn,如下所示:

     $(document).ready(function(){ setInterval(function(){ $('.live-stream ul').each(function(){ $(this).hide().load('tx.php').fadeIn("1000"); }); }, 1000); }); 

    或者用css隐藏元素:

     display: none; 

    编辑:应该是这样的,但它没有经过测试……

     $(document).ready(function(){ setInterval(function(){ var streamListElement = $(document.createElement("li")).load('tx.php').hide(); $('.live-stream ul').append( streamListElement ).find(":hidden").fadeIn("3000"); }, 1000); }); 

    我认为你不能直接在load()上使用动画。 但这是我使用的技巧:

     $("#id").animate({opacity: 0},1000); $("#id").load(url); $("#id").animate({opacity: 1},1000); 

    元素不显示,只是变得透明。 它看起来一样。