其他分享
首页 > 其他分享> > 简易分页器

简易分页器

作者:互联网

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>简易分页器</title>
    <script src="./js/jquery-3.5.1.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      li {
        list-style: none;
      }
      .list {
        display: flex;
        flex-wrap: wrap;
      }
      .list li {
        width: 100px;
        height: 100px;
        background-color: lightblue;
        text-align: center;
        line-height: 100px;
        margin: 10px;
      }
      .ye {
        display: flex;
        justify-content: center;
        margin-top: 50px;
      }
      .ye li {
        width: 50px;
        height: 50px;
        background-color: lightcoral;
        margin: 5px;
        text-align: center;
        line-height: 50px;
      }
    </style>
  </head>
  <body>
    <ul class="list">
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
      <li>7</li>
      <li>8</li>
      <li>9</li>
      <li>10</li>
      <li>11</li>
      <li>12</li>
      <li>13</li>
      <li>14</li>
      <li>15</li>
      <li>16</li>
      <li>17</li>
      <li>18</li>
      <li>19</li>
      <li>20</li>
      <li>21</li>
      <li>22</li>
      <li>23</li>
      <li>24</li>
      <li>25</li>
      <li>26</li>
      <li>27</li>
      <li>28</li>
      <li>29</li>
      <li>30</li>
      <li>31</li>
      <li>32</li>
      <li>33</li>
      <li>34</li>
      <li>35</li>
      <li>36</li>
      <li>37</li>
      <li>38</li>
      <li>39</li>
      <li>40</li>
    </ul>
    <ul class="ye"></ul>
  </body>
  <script>
    $(function () {
      // 核心
      function fenyeqi(dom1, dom2, num) {
        for (var i = 0; i < $(dom1).length / num; i++) {
          $("<li>" + (i + 1) + "<li>").appendTo(dom2);
          $("" + dom2 + " li:empty").remove();
        }
        common(dom1, num, 1);
        $("" + dom2 + " li").click(function () {
          common(dom1, num, $(this).index() + 1);
        });
        function common(dom1, num, e) {
          $(dom1).css({
            display: "none",
          });
          for (var i = num * e - num; i <= num * e - 1; i++) {
            $("" + dom1 + ":eq(" + i + ")").css({
              display: "block",
            });
          }
        }
      }
      //   参数说明,第一个参数表示需要分页的主体元素,第二个参数表示分页器所在的元素,第三个参数表示一页显示多少个元素
      fenyeqi(".list li", ".ye", 6);
    });
  </script>
</html>

 

标签:function,分页,height,简易,num,dom1,dom2,li
来源: https://blog.csdn.net/KEY2018/article/details/116175866