我正在使用this pagination plugin。使用Easy Paginate jQuery插件在同一頁面上創建多個分頁
在他的解釋下,作者提到:
如果你想在同一個頁面上創建多個paginations,有 記住,這個插件使用的ID,所以你需要 目標控制按鈕爲每個分頁定義控件ID參數。
在我的網頁,我已經定義了兩個控件:
1.
$('#port').easyPaginate({
step:2
});
2.
$('#blog_posts').easyPaginate({
step:1
});
只有在第一個廣告id='port'
工作。
有沒有人有任何想法,我怎麼能得到這個工作?
這裏是爲了方便您的腳本:
(function($) {
$.fn.easyPaginate = function(options){
var defaults = {
step: 4,
delay: 100,
numeric: true,
nextprev: true,
auto:false,
pause:4000,
clickstop:true,
controls: 'pagination',
current: 'current'
};
var options = $.extend(defaults, options);
var step = options.step;
var lower, upper;
var children = $(this).children();
var count = children.length;
var obj, next, prev;
var page = 1;
var timeout;
var clicked = false;
function show(){
clearTimeout(timeout);
lower = ((page-1) * step);
upper = lower+step;
$(children).each(function(i){
var child = $(this);
child.hide();
if(i>=lower && i<upper){ setTimeout(function(){ child.fadeIn('fast') }, (i-(Math.floor(i/step) * step))*options.delay); }
if(options.nextprev){
if(upper >= count) { next.fadeOut('fast'); } else { next.fadeIn('fast').css({'display':'inline-block'}); };
if(lower >= 1) { prev.fadeIn('fast').css({'display':'inline-block'}); } else { prev.fadeOut('fast'); };
};
});
$('li','#'+ options.controls).removeClass(options.current);
$('li[data-index="'+page+'"]','#'+ options.controls).addClass(options.current);
if(options.auto){
if(options.clickstop && clicked){}else{ timeout = setTimeout(auto,options.pause); };
};
};
function auto(){
if(upper <= count){ page++; show(); }
};
this.each(function(){
obj = this;
if(count>step){
var ol;
var pages = Math.floor(count/step);
if((count/step) > pages) pages++;
ol = $('<ol id="'+ options.controls +'"></ol>').insertAfter(obj);
if(options.nextprev){
prev = $('<li class="prev">« Previous</li>')
.hide()
.appendTo(ol)
.click(function(){
clicked = true;
page--;
show();
});
};
if(options.numeric){
for(var i=1;i<=pages;i++){
$('<li data-index="'+ i +'">'+ i +'</li>')
.appendTo(ol)
.click(function(){
clicked = true;
page = $(this).attr('data-index');
show();
});
};
};
if(options.nextprev){
next = $('<li class="next">Next »</li>')
.hide()
.appendTo(ol)
.click(function(){
clicked = true;
page++;
show();
});
};
show();
};
});
};
})(jQuery);
謝謝F. Orvalho的重寫。我是新來的論壇,每一點都有所幫助。現在只需要有人回答實際問題。 – 2012-08-11 15:55:46