无法在 jquery 中链接动画

发布于 2024-08-19 11:32:33 字数 482 浏览 1 评论 0原文

我有一个使用 css 代码 {display:none;} 隐藏的列表,

现在我使用 jquery 代码对列表进行动画处理(li's),

var numb = $("ol#update li").length;
 for(j=0; j < numb; j++) {                    
  $("ol#update li").eq(j).animate({
    height: 'show',
opacity: 'show'
}, {duration:1000});
  }

我需要一个接一个地对项目进行动画处理,

page

但所有的 li 都同时被动画化,我不可能明白为什么。

I have a list which is hidden using css code {display:none;}

now i am using the jquery code to animate the list (li's)

var numb = $("ol#update li").length;
 for(j=0; j < numb; j++) {                    
  $("ol#update li").eq(j).animate({
    height: 'show',
opacity: 'show'
}, {duration:1000});
  }

I need to animate the items one after the other

there's an example in this page

but all the li's are being animated all at once and i cannot possibly see why.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2024-08-26 11:32:33

只需使用这个即可:

var $li = $("ol#update li");
function animate_li(){
   $li.filter(':first')
      .animate({
         height:  'show',
         opacity: 'show'
      }, 1000, function(){
        animate_li();
      });
  $li = $li.not(':first');
}
animate_li();

基本上它会抓取所有 li ,然后一个接一个地对它们进行动画处理。同时,每次迭代都会从列表中删除第一个元素。如果您希望它以相反的方式设置动画,请将两次出现的 :first 替换为 :last

Just use this instead:

var $li = $("ol#update li");
function animate_li(){
   $li.filter(':first')
      .animate({
         height:  'show',
         opacity: 'show'
      }, 1000, function(){
        animate_li();
      });
  $li = $li.not(':first');
}
animate_li();

Basically it grabs all the lis, and then one by one animates them in. At the same time, each iteration removes the first element from the list. If you wanted it to animate the other way around, replace both occurances of :first with :last.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文