2012-08-10 103 views
0

我正在使用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">&laquo; 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 &raquo;</li>') 
         .hide() 
         .appendTo(ol) 
         .click(function(){ 
          clicked = true;   
          page++; 
          show(); 
         }); 
       }; 

       show(); 
      }; 
     }); 

    }; 

})(jQuery); 
+0

谢谢F. Orvalho的重写。我是新来的论坛,每一点都有所帮助。现在只需要有人回答实际问题。 – 2012-08-11 15:55:46

回答

0

使用jQuery,创建过要分页列表cylces的功能。用普通的类标记它们,以确保你没有选择页面上的所有列表。

HTML

<div id="test_1" class="paginateMe"> 
    <ul> 
    </ul> 
    <div class="clear"></div> 
</div> 

<div id="test_2" class="paginateMe"> 
    <ul> 
    </ul> 
    <div class="clear"></div> 
</div> 

JS:

$('div.paginateMe').each(function(index, element) { 
    $this = $('#'+$(this).attr('id')+' ul'); 

    $this.easyPaginate({ step:1 }); 
}); 

你也可以只针对一个UL与普通类,而不是它嵌套在一个DIV像我上面那样。

+0

谢谢@opanitch回复。不过,如果我想每个人都有不同的分页步骤,该怎么办?比方说,使用你的例子,div#test_1将有步骤:5和div:test_2将有步骤:10? – 2012-08-20 17:53:37

+0

然后在for.each循环中创建一个条件。 if(div_1){$ this.easyPaginate({step:5});} if else(div_2){$ this.easyPaginate({step:10});} – opanitch 2012-09-06 16:10:03

0

我解决了不同的方式

$('ul.easypagination1').easyPaginate({ 
     step:20, 
     delay:0, 
     controls:'easy-pagination-1' 
     }); 

    $('ul.easypagination2').easyPaginate({ 
     step:20, 
     delay:0, 
     controls:'easy-pagination-2' 
     }); 

它的工作原理,但你必须把更多的代码和更多的CSS,我tryed opanitch的代码,但它不适合我的作品,现在我对jQuery的1.7.2 ...不知道。

相关问题