javascript - 如何多次附加元素(向下滑动)

标签 javascript jquery html css

当我点击带有 moree 类的 div 时,我想附加 5 个 li 元素。 它工作正常,但是当我点击更多时,我想在列表的末尾添加这些按钮。现在元素处于乞讨状态。 Furturmore 有没有办法附加效果滑落? 这是我的片段:

$(document).ready(function () {
   for (var i = 0; i < 5; i++) {
        $(".moree").click(function () {
             $(this).closest('.content').append('<ol ><li>Title 2</li></ol>');
        });
   }  

});
ol > li { 
   list-style:none; 
   padding-top:10px; 
   border:1px solid green;
   margin-top:10px;
}
.moree { 
   width:30px; 
   background:yellow;
}
<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
    <div class="content">
    <ol>
    <li>title</li>
     <div class="moree">Add 5</div>
    </ol>
    </div>
</body>
</html>

谢谢。

最佳答案

你是这个意思吗?它仅通过向下滑动动画略微改进了您的示例。

$(document).ready(function () {
  $(".moree").click(function () {
    var delay = 0;
    for (var i = 0; i < 5; i++) {              
      $(this)
        .prev()
        .append('<li style="display:none">Title 2</li>')
        .children()
        .last()
        .hide()
        .delay(delay)
        .slideDown(400);
      delay += 400;
    }
  });
});
ol > li{ list-style:none; padding-top:10px; border:1px solid green;margin-top:10px;}
.moree{ width:30px; background:yellow;}
<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
    <div class="content">
      <ol>
        <li>title</li>
      </ol>
      <div class="moree">Add 5</div>
    </div>
</body>
</html>

关于javascript - 如何多次附加元素(向下滑动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39815181/

相关文章:

javascript - 切换三个或更多 div 的可见性

html - 3列响应式布局

javascript - 将具有相同类名的表单输入字段放入数组中

javascript - Uncaught ReferenceError : Vue is not defined

javascript - 我如何使用 XML 设计样式

javascript - jQuery + CSS : Creating a pulsating heart

javascript - 使用 jQuery .hide() 和 CSS 媒体查询基于屏幕分辨率进行菜单切换

javascript - 使用 jQuery 切换 CSS 类

javascript - 如何使用 redux 工具包查询 (RTKQ) 访问 transformResponse 中的查询参数?

html - 用文本包裹 anchor 元素