简体   繁体   English

客户端分页

[英]Client-side pagination

I have N number of html elements. 我有N个html元素。 Is it possible to hide the N - 10 bottom elements with jQuery and then create a "Load more" button to show another 10 elements? 是否可以使用jQuery隐藏N-10个底部元素,然后创建“加载更多”按钮以显示另外10个元素?

I mean that when the page loads, only the 10 first elements should be visible, and when I click "Load more", the 20 first elements is visible, and when I click again, the 30 first elements is visible, etc. 我的意思是,页面加载时,只有10个第一个元素应该可见,而当我单击“加载更多”时,这20个第一个元素是可见的,再次单击时,这30个第一个元素是可见的,依此类推。

Would it be something like 会不会像

$('li').slice(-($('li').length - 10)).hide();

and then 接着

var num_visible = 10;
$('#loadMore').click(function () {
  $('li').slice(num_visible, num_visible + 10).show();
  num_visible += 10;
});

You might need to add some further validation – this just shows the general idea – for your specific use case, but would something like this work? 您可能需要针对您的特定用例添加一些进一步的验证(这仅显示了总体思路),但是这样的工作可行吗?

var currShowing = 10;
changeShowing()
function changeShowing() {
 $('div').each(function(index, value) {
    if (index < currShowing - 1 ) {
      $(this).show();
    } else {
      $(this).hide();
    }
  })   
}

function showMore() {
  currShowing += 10;
  changeShowing();
}

http://codepen.io/mwvanmeurs/pen/VPoORq http://codepen.io/mwvanmeurs/pen/VPoORq

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM