How to create pagination like Stack Overflow site

后端 未结 6 2070
情歌与酒
情歌与酒 2021-01-05 17:13

how to create pagination like stackoverflow?

相关标签:
6条回答
  • 2021-01-05 17:18

    You can create pagination using twitter bootstrap with less than 10 line of code like this example of pagination using twitter bootstrap

    0 讨论(0)
  • 2021-01-05 17:23

    This works very great for me. Since this is no javascript, users with javascript disabled can use it too.

    0 讨论(0)
  • 2021-01-05 17:24

    Just include jquery and jquery pagination plugin in your page and use this,

    $(document).ready(function() {
      $(".pager").pagination(300, {
        callback: pagecallback,
        current_page: 0,
        items_per_page: 5,
        num_display_entries: 5,
        next_text: 'Next',
        prev_text: 'Prev',
        num_edge_entries: 1
      });
    });
    .pager {
      margin-bottom: 10px;
      margin-top: 10px;
    }
    .page-numbers {
      border: 1px solid #CCCCCC;
      color: #808185;
      display: block;
      float: left;
      font-family: Trebuchet MS, Helvetica, sans-serif;
      font-size: 130%;
      margin-right: 3px;
      padding: 4px 4px 3px;
      text-decoration: none;
    }
    .page-numbers.desc {
      border: medium none;
    }
    .page-numbers:hover {
      text-decoration: none;
    }
    .pager a {
      color: #808185;
      cursor: pointer;
      text-decoration: none;
      outline: none;
    }
    .pager a:hover {
      text-decoration: underline;
    }
    .pager a:visited {
      color: #808185;
      outline: none;
    }
    .page-numbers.next,
    .page-numbers.prev {
      border: 1px solid #CCCCCC;
    }
    .page-numbers.current {
      background-color: #808185;
      border: 1px solid #808185;
      color: #FFFFFF;
      font-weight: bold;
    }
    .page-numbers.dots {
      border: 1px solid #FFFFFF;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <div class="pager" id="Pagination">
      <!-- the container for your first pagination area -->
    </div>

    0 讨论(0)
  • 2021-01-05 17:28

    Use Jquery plugin pagination:

    http://plugins.jquery.com/project/pagination

    0 讨论(0)
  • 2021-01-05 17:39

    You didn't say what server side technology you are using but if you want a pure client side solution you may take a look at the jQuery Pagination plugin. Here's a demo page.

    0 讨论(0)
  • 2021-01-05 17:42

    you can use this function too:

    function makePaging(totalPages, pageIndex) {
        var oPaging, i, j, k;
        var totalPages = parseInt(totalPages);
    
        pageIndex++;
    
        i = pageIndex;
        j = pageIndex - 1;
        k = pageIndex + 1;
    
        var oBefore, oAfter;
        oBefore = "";
        oAfter = "";
    
        while (j != 0 && j != i - 6) {
            oBefore = "<a class='Page' href='#' data-index='" + (j - 1) + "'>" + j + "</a>&nbsp;" + oBefore;
            j--;
        }
    
        for (; k < totalPages + 1 && k < i + 6; k++) {
            oAfter += "<a class='Page' href='#' data-index='" + (k - 1) + "'>" + k + "</a>&nbsp;";
        }
    
        oPaging = oBefore + "<a class='CurPage' href='#' rel='' style='color:Red;'>" + i.toString() + "</a>&nbsp;" + oAfter;
    
        return oPaging;
    }
    
    0 讨论(0)
提交回复
热议问题