javascript - 在 HTML 中加载前 3 个图像元素,单击 “load more” 以显示接下来的 2 个元素

标签 javascript jquery html css

我有一个 ID 为#myList 的 div,它包含 8 个子 div,每个子 div 都有图像。

我想做的是默认加载前 3 张图片,然后当我们点击加载更多

我已经关注了这个 jsfiddle

我的代码如下,类似但由于未知原因无法运行

        <div id="mylist" class="autoplay123company">

          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

            <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/gtbank__1.jpg" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

            <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/partner-MTN.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

            <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/Partner-airtel.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

            <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/06/page-1.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

            <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/Partner-citibank.png" alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-1">

            <img src=" " alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-1">

            <img src=" " alt="" style="height:100px !important;" width="150" height="100">

          </div>
          <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-1">

            <img src=" " alt="" style="height:100px !important;" width="150" height="100">

          </div>
        </div>
        <div id="loadMore">Load more</div>
        <div id="showLess">Show less</div>
#myList div.col-lg-4 {
  display: none;
}

#loadMore {
  color: green;
  cursor: pointer;
}

#loadMore:hover {
  color: black;
}

#showLess {
  color: red;
  cursor: pointer;
}

#showLess:hover {
  color: black;
}
<div id="mylist" class="autoplay123company">

  <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

    <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/gtbank__1.jpg" alt="" style="height:100px !important;" width="150" height="100">

  </div>
  <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

    <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/partner-MTN.png" alt="" style="height:100px !important;" width="150" height="100">

  </div>
  <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

    <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/Partner-airtel.png" alt="" style="height:100px !important;" width="150" height="100">

  </div>
  <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

    <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/06/page-1.png" alt="" style="height:100px !important;" width="150" height="100">

  </div>
  <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="0">

    <img src=" http://realbusinessanalytics.com/wp-content/uploads/2018/07/Partner-citibank.png" alt="" style="height:100px !important;" width="150" height="100">

  </div>
  <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-1">

    <img src=" " alt="" style="height:100px !important;" width="150" height="100">

  </div>
  <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-1">

    <img src=" " alt="" style="height:100px !important;" width="150" height="100">

  </div>
  <div class="col-lg-4 d-flex justify-content-center" style="" aria-hidden="true" tabindex="-1">

    <img src=" " alt="" style="height:100px !important;" width="150" height="100">

  </div>
</div>
<div id="loadMore">Load more</div>
<div id="showLess">Show less</div>

请帮我实现它。这是 my edited jsfiddle

最佳答案

您指的是 JS 和 CSS 中的 #myList,但 div 实际上是 mylist。如果您更正 div ID 上的大小写,那么一切都应该按预期工作。

关于javascript - 在 HTML 中加载前 3 个图像元素,单击 “load more” 以显示接下来的 2 个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51798447/

相关文章:

javascript - 这个网页是如何动态加载数据的?

javascript - OctoberCMS Ajax 表单按取消后仍提交

javascript - 预制尚未显示 HTML 元素?

javascript - Google 日历嵌入事件信息

php - 选择禁用的字段不插入

php - htmlspecialchars 的问题

javascript - API ajax 请求的进度条仅在从 API 获得响应后才开始加载

javascript - jQuery 验证字段 :getting error messages to disappear upon entering valid information

html - 如何修改我的脚本以在数据库表中添加行回调函数

html - div 中的表? IE7 兼容性问题 - 寻找资源来扩展有关如何处理 IE7 问题的知识