如何让 Twitter“显示更多”有效果但没有ajax?
我有一个包含 50 项的无序列表。我想一次只显示 10 个,并在底部有一个“更多”链接。 完全像这样,只是没有ajax,因为我不需要它。
您能否给我一些提示或指导我如何实现此效果的教程?
谢谢你!
编辑:感谢 Royi Namir 提供的链接。我试图在 10 个列表中每页显示 2 个项目,但无法弄清楚我做错了什么...
JS
function pageselectCallback(page_index, jq){
// Get number of elements per pagionation page from form
var items_per_page = 2;
var max_elem = Math.min((page_index+1) * items_per_page, members.length);
var newcontent = '';
// Iterate through a selection of the content and build an HTML string
for(var i=page_index*items_per_page;i<max_elem;i++)
{
newcontent = jQuery('#hiddenresult div.result:eq('+i+')').append();
}
// Replace old content with new content
$('#Searchresult').html(newcontent);
// Prevent click eventpropagation
return false;
}
/**
* Initialisation function for pagination
*/
function initPagination() {
// Create content inside pagination element
$("#Pagination").pagination(10, {
callback: pageselectCallback,
load_first_page:true,
items_per_page:2
});
}
// When document is ready, initialize pagination
$(document).ready(function(){
initPagination();
});
HTML:
<div id="Pagination"></div>
<br style="clear:both;" />
<div id="Searchresult">
This content will be replaced when pagination inits.
</div>
<!-- Container element for all the Elements that are to be paginated -->
<div id="hiddenresult" style="display:none;">
<div class="result">111</div>
<div class="result">222</div>
<div class="result">333</div>
<div class="result">444</div>
</div>
编辑#2:找到了我的答案:D http://th3silverlined.com/2010/04/15/pajination-a-jquery-pagination-plugin/
I have an unordered list of 50 items. I want to show only 10 at a time with a More link at the bottom. Exactly like this only without ajax as I don't need it.
Could you please give me a tip or direct me to a tutorial on how I can achieve this effect?
Thank you!
EDIT: Thanks Royi Namir for the link. I'm trying to show 2 items per page from a list of 10 but can't figure what I'm doing wrong...
JS
function pageselectCallback(page_index, jq){
// Get number of elements per pagionation page from form
var items_per_page = 2;
var max_elem = Math.min((page_index+1) * items_per_page, members.length);
var newcontent = '';
// Iterate through a selection of the content and build an HTML string
for(var i=page_index*items_per_page;i<max_elem;i++)
{
newcontent = jQuery('#hiddenresult div.result:eq('+i+')').append();
}
// Replace old content with new content
$('#Searchresult').html(newcontent);
// Prevent click eventpropagation
return false;
}
/**
* Initialisation function for pagination
*/
function initPagination() {
// Create content inside pagination element
$("#Pagination").pagination(10, {
callback: pageselectCallback,
load_first_page:true,
items_per_page:2
});
}
// When document is ready, initialize pagination
$(document).ready(function(){
initPagination();
});
HTML:
<div id="Pagination"></div>
<br style="clear:both;" />
<div id="Searchresult">
This content will be replaced when pagination inits.
</div>
<!-- Container element for all the Elements that are to be paginated -->
<div id="hiddenresult" style="display:none;">
<div class="result">111</div>
<div class="result">222</div>
<div class="result">333</div>
<div class="result">444</div>
</div>
EDIT #2: Found my answer :D http://th3silverlining.com/2010/04/15/pajination-a-jquery-pagination-plugin/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不想使用 AJAX,请加载完整内容。
您可以使用 jQuery 和 CSS 隐藏元素。以
show()
和hide()
为例。您也可以通过点击显示更多链接来切换此链接,并将此链接替换为显示更少链接。
http://api.jquery.com/show/
http://api.jquery.com/hide/
Load the complete content if you don't want to use AJAX.
You can hide elements with jQuery and CSS. Take for example a look at
show()
andhide()
.You can toggle this on click on your show more link and replace this link with a show less link instead, too.
http://api.jquery.com/show/
http://api.jquery.com/hide/
确保
http://plugins.jquery.com/project/pagination
演示在这里:
http://d-scribe.de/webtools/jquery-pagination/demo/demo_options.htm
sure
http://plugins.jquery.com/project/pagination
demo is here :
http://d-scribe.de/webtools/jquery-pagination/demo/demo_options.htm
我能想到的最简单的方法是通过一些隐藏显示链接。
将这个简单的代码添加到页面底部。
然后只需将每组十个项目包装起来,例如
对于此代码的完整解释,请转到 http://andylangton.co.uk/articles/javascript/jquery-show-hide-multiple-elements/
The very simplest way I can think of doing this is via a few hide show links.
add this simple code to the bottom of your page.
then just wrap each group of ten items like
For a full expiation of this code goto http://andylangton.co.uk/articles/javascript/jquery-show-hide-multiple-elements/