0

我正在使用这个分页插件

在他的解释的底部,作者提到:

如果您想在同一页面上创建多个分页,请记住此插件使用 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);
4

2 回答 2

0

使用 JQuery,创建一个函数,用于循环浏览要分页的列表。用通用类标记它们,以确保您没有选择页面上的所有列表。

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 中。

于 2012-08-17T17:32:00.773 回答
0

我以不同的方式解决了

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

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

它可以工作,但您必须添加更多代码和更多 css,我尝试了 opanitch 的代码,但它对我不起作用,现在我在 jquery 1.7.2 上......不知道。

于 2012-09-18T12:45:27.403 回答