jQuery Pagination by div height (not item)

后端 未结 4 1524
野趣味
野趣味 2021-01-03 08:21

I am interested in using jQuery to create automatic pagination for content based on the height of the content and the div, rather than by number of items. Most pagination ex

4条回答
  •  无人及你
    2021-01-03 08:34

    Sounds to me like you just need to implement $.scrollTo(): I just worked-up the following concept using a single "Advance Forward" button (Note: You must have jQuery and the scrollTo plugin referenced:

    
    
    

    --

    var numElmnts = $("#pagination p").length;
    var lastIndex = 0;
    $(".next").click(function(){
      var nextIndex = (lastIndex >= (numElmnts-1)) ? 0 : (lastIndex+1) ;
      var nextParag = $("#pagination p:eq("+nextIndex+")");
      $("#pagination").animate({ height: $(nextParag).outerHeight() }, 800, "linear", function(){
        $("#pagination").scrollTo(nextParag, 800);
      });
      lastIndex = nextIndex;
    });
    

提交回复
热议问题