javascript - jQuery - 使用渐变动画将列表项附加到现有列表

标签 javascript jquery html animation effects

所以我有一个列表:

<ul>
 <li> bla bla </li>
 <li> bla bla </li>
 ...
</ul>

<a> click me </a>

当您单击链接时,将运行 ajax 请求来检索更多列表项。

如何将这些新项目附加到现有列表(点所在的位置),并为它们一一设置动画,例如使用。下滑,小停顿,下一个项目滑下,再次小停顿等等...?

现在我有这个,它可以同时为所有列表项设置动画:

  $.ajax({
      ... 
      success: function(response){

           $(response).appendTo("ul").hide().animate({
            "height": "show",
            "marginTop": "show",
            "marginBottom": "show",
            "paddingTop": "show",
            "paddingBottom": "show"},
            { duration: 333 });
      ...

最佳答案

您可以添加 .delay()基于索引,如下所示:

jQuery(response).appendTo("ul").hide().each(function(i) {
   jQuery(this).delay(400*i).animate({
        "height": "show",
        "marginTop": "show",
        "marginBottom": "show",
        "paddingTop": "show",
        "paddingBottom": "show"}, 333);
});

这会立即运行第一个(400*0),第二个 400ms(400*1)稍后运行(67ms 延迟),等等。只需将延迟调整到您想要的任何值,但这是获得一个的简单方法-逐一动画风格。

关于javascript - jQuery - 使用渐变动画将列表项附加到现有列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4170162/

相关文章:

jquery - 获取委托(delegate)事件绑定(bind)到的根元素 - jQuery

javascript - 将文本区域输入字符串转换为类型对象

javascript - 在 Javascript 中,如何在不指定 rgb 的情况下设置 rgba?

javascript - 页面上的条件测试模块(如果存在) - 使用 Cypress

javascript - Google Analytics - 旧版本和新版本有什么区别?

javascript - 编写一个可以与带有 axios 输出的 then() 链接的函数

javascript - 如何将我的整个网页调整到 65%

jquery - 突出显示选项卡式元素(使用 jQuery/CSS/任何内容)

jquery - 获取 jQuery 的 SharePoint 表单字段的 ID

html - div 悬停不应用颜色 CSS