分页效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分页效果(face项目)</title>
    <script src="src/jquery-1.11.1.js"></script>
    <script src="src/jquery.pagebar.1.0.0.js"></script>
    <link rel="stylesheet" href="css/pagebar.css">
</head>
<body>

    <div class="pagebar" id="pagebar"></div>

    <script>

        initPageBar(5, 25,30,160);
        function initPageBar(pageNo, totalPage,pageSize,rowCount) {
         /*   if (pageInstance != null) {
                // 处理分页
                $.fn.setTotalPage(pageInstance,pageNo, totalPage,pageSize,rowCount);
                return;
            }*/
            pageInstance = $.fn.jpagebar({
                renderTo : $(".pagebar"),
                totalpage : totalPage,
                currentPage : pageNo,
                pageSize : pageSize,
                rowCount : rowCount,
                pageNameCssName : 'pageName',
                onClickPage : function(pageIndex,pageSize) {
                    $.fn.setCurrentPage(this, pageIndex,pageSize);
                    pageNo = pageIndex;
                    pageSize=pageSize;
                }
            });

        }


    </script>
</body>
</html>

这里写图片描述

///jquery.pagebar.1.0.0.js内容如下:


(function($) {
    $.extend($.fn, {
        jpagebar : function(setting) {
            var pb = $.extend({
                // pagebar 对象div
                renderTo : $(document.body),
                // 总页码
                totalpage : 0,
                // 当前页码
                currentPage : 0,
                //每页显示条数
                pageSize:0,
                //总条数
                rowCount:0,
                // 分页条样式
                pagebarCssName : 'pagebar',
                // 页码样式
                pageNumberCssName : 'page_number',
                // 首页、Pre、Next、尾页样式
                pageNameCssName : 'pageName',
                // 选中首页、Pre或Next、尾页样式
                currentPageNameCssName : 'current_pageName',
                // 当前选中页码样式
                currentPageNumberCssName : 'current_page_number',
                // 显示总页码样式
                totalpageNumberCssName : 'totalpage_number',
                // 点击页码action
                onClickPage : function(pageIndex,pageSize) {

                }
            }, setting);

            pb.resetPagebar = function() {
                var _this = this;
                _this.renderTo = (typeof _this.renderTo == 'string' ? $(_this.renderTo) : _this.renderTo);

                /*
                 * ----------> html : <div> ---->pagebar <a>首页</a> <a>Pre</a> <a>&nbsp;</a>... ----> 显示页码 <a>Next</a> <a>尾页</a> <span class="show_page_detail"> ---->显示信息 <span
                 * class="current_page">currentpage</span> ----> 显示当前页码 <span>/</span> <span class="total_page">totalpage</span> ----> 显示总页码 </span> </div> <-----------
                 */
                var pagebar = _this.renderTo;
                pagebar.attr('class', _this.pagebarCssName);

                // 清空分页导航条
                pagebar.empty();


                // 分页
                var front_block = parseInt(_this.currentPage) - 4;// 当前页码前面一截,原来是5
                var back_block = parseInt(_this.currentPage) + 4;// 当前页码后面一截,原来是5

                // 处理首页、Pre
                if (_this.currentPage == 1) {
                    // 当前页为第一页
                    $('<a>首页</a> ').attr('class', _this.pageNameCssName + ' ' + _this.currentPageNameCssName).appendTo(pagebar);
                    $('<a>上一页</a> ').attr('class', _this.pageNameCssName + ' ' + _this.currentPageNameCssName).appendTo(pagebar);

                }
                else {
                     //当前页大于第一页
                    $('<a>首页</a> ').attr('class', _this.pageNameCssName).bind("click", function() {
                        _this.onClickPage(1,pageSize);
                  }).appendTo(pagebar);
                    $('<a>上一页</a> ').attr('class', _this.pageNameCssName).bind("click", function() {
                        _this.onClickPage(_this.currentPage - 1,pageSize);
                    }).appendTo(pagebar);
                }

                // 处理数字页码

                if (_this.totalpage == 1) {
                    // 共1页
                    $('<a>1</a> ').attr('class', _this.currentPageNumberCssName).bind("click", function() {
                        _this.onClickPage(1,pageSize);
                    }).appendTo(_this.renderTo);

                }
                else {
                    // 有多页
                    var tempBack_block = _this.totalpage;
                    var tempFront_block = 1;
                    if (back_block < _this.totalpage)
                        tempBack_block = back_block;
                    if (front_block > 1)
                        tempFront_block = front_block;

                    for ( var i = tempFront_block; i <= tempBack_block; i++) {
                        if (_this.currentPage == i) {
                            // 当前页
                            $('<a>' + i + '</a> ').attr('class', _this.pageNumberCssName + ' ' + _this.currentPageNumberCssName).appendTo(pagebar);
                        }
                        else {
                            $('<a>' + i + '</a> ').attr('class', _this.pageNumberCssName).bind("click", function() {
                                _this.onClickPage(this.innerHTML,pageSize);
                            }).appendTo(pagebar);

                        }
                    }
                }

                // Next, 尾页 处理
                if (_this.currentPage == _this.totalpage) {
                    // 当前页为最后一页
                    $('<a>下一页</a> ').attr('class', _this.pageNameCssName + ' ' + _this.currentPageNameCssName).appendTo(pagebar);
                  $('<a>尾页</a> ').attr('class', _this.pageNameCssName + ' ' + _this.currentPageNameCssName).appendTo(pagebar);
                }
                else {
                    $('<a>下一页</a> ').attr('class', _this.pageNameCssName).bind("click", function() {
                        _this.onClickPage(parseInt(_this.currentPage) + 1,pageSize);
                    }).appendTo(pagebar);
                    $('<a>尾页</a> ').attr('class', _this.pageNameCssName).bind("click", function() {
                        _this.onClickPage(_this.totalpage,pageSize);
                   }).appendTo(pagebar);
                }


                var pager='';
                var pageSize=_this.pageSize;
                var rowCount=_this.rowCount;
                pager += "<div class=\"pageTextBox\"  id=\"selectRowCount\">共"+rowCount+"项,每页显示 <select id=\"pageSize\" name=\"pageSize\"  class=\"input_ff\"  onchange=\"$.fn.changeTotal()\">";               
                if(pageSize==10){
                    pager += " <option value=\"10\" selected=\"selected\" > 10 </option>";
                }else{
                    pager += " <option value=\"10\"  > 10 </option>";
                }
                if(pageSize==15){
                    pager += " <option value=\"15\" selected=\"selected\" > 15 </option>";
                }else{
                    pager += " <option value=\"15\"  > 15 </option>";
                }
                if(pageSize==20){
                    pager += " <option value=\"20\" selected=\"selected\" > 20 </option>";
                }else{
                    pager += " <option value=\"20\"  > 20 </option>";
                }
                if(pageSize==30){
                    pager += " <option value=\"30\" selected=\"selected\" > 30 </option>";
                }else{
                    pager += " <option value=\"30\"  > 30 </option>";
                }
                if(pageSize==50){
                    pager += " <option value=\"50\" selected=\"selected\" > 50 </option>";
                }else{
                    pager += " <option value=\"50\"  > 50 </option>";
                }
                if(pageSize==100){
                    pager += " <option value=\"100\" selected=\"selected\" > 100 </option>";
                }else{
                    pager += " <option value=\"100\"  > 100 </option>";
                }
                pager += " </select>条记录" ;
                pager +="<div class=\"goPage\">";
                pager +='到<input text id=\"pageNoText\" onkeyup="$.fn.limitSize('+_this.totalpage+')" placeholder="'+_this.totalpage+'" style="width:40px;">页';
                pager +='<span class="oBtn goBtn" onclick="$.fn.jumpPage()" >跳转</span>'; 
                pager +="</div>";
                pager +="</div>";

                $(pager).appendTo(pagebar);
                if (totalpage = 0) {
                    return;
                }

                 /*红色字体显示当前页
                $('<span>共'+_this.totalpage+'页</span> ').attr('class',_this.totalpageNumberCssName).appendTo(pagebar);
                 $('&nbsp;&nbsp;&nbsp;<span>当前'+_this.currentPage+'</span> ').attr('class',_this.currentPageNumberCssName).appendTo(pagebar);
                 $('<span>/</span>').appendTo(pagebar);
                 $('<span>共'+_this.totalpage+'页</span> ').attr('class',_this.totalpageNumberCssName).appendTo(pagebar);

                 pagebar.find("a").attr('class',_this.pageNumberCssName);*/
            };
            pb.resetPagebar();
            return pb;
        },

        changeTotal : function() {
            $('#searchBtn').click();
        },
        limitSize : function(renderTo) {
            var text = $("#pageNoText").val();
            text=text.replace(/\D/g,'');
            if(text > renderTo){
                $("#pageNoText").val(renderTo);
            }else if(text <= 0 ){
                $("#pageNoText").val(1);
            }else{
                $("#pageNoText").val(text);
            }

        },
        jumpPage : function(_this){
            var pageNoText = $("#pageNoText").val();
            var pageSize= $("#pageSize option:selected").val();
            if(pageNoText != ""){
                search(pageNoText,pageSize,"next");
            }
        },
        setCurrentPage : function(_this, currentPage,pageSize) {
            _this.currentPage = currentPage;
            _this.pageSize = pageSize;
            _this.resetPagebar(_this);
        },
        getCurrentPage:function(_this) {
            return _this.currentPage;
        },
        setTotalPage : function(_this,currentPage,totalpage,pageSize,rowCount) {
            _this.currentPage = currentPage;
            _this.totalpage = totalpage;
            _this.pageSize = pageSize;
            _this.rowCount = rowCount;
            _this.resetPagebar(_this);
        }

    });
})(jQuery);
 /*css代码如下: */
.pagebar {
    width:100%;
    margin:10px 0 0 0;
    position:relative;
    display:inline-block;
    padding:10px;
    background:#e5eee2;
    border-top:2px solid #309a0a;
    z-index:12;
}


#pagebar{position:fixed;bottom:0;left:0;}

#selectRowCount{line-height:27px;}





.pagebar a { 
    color: #5A9D0F;
    border: 1px solid #5A9D0F;
    cursor: pointer;
    height: 25px;
    text-align: center;
    line-height: 25px;
    display: inline-block;
    margin-left: 5px;
    float: left;
}


.pagebar a:hover,.pagebar a.on { /* background: #ededed;
    color: #666; */
    color: #FFF;
    background-color: #5A9D0F;
}



.pageName { /* border: solid 1px #AAE;
    cursor: pointer;
    color: #5F7690; */
    width: 80px;
}

.page_number { /* float: left;
    padding: 0.3em 0.5em;
    margin-right: 5px;
    margin-bottom: 5px;
    text-decoration: none;
    border: solid 1px #AAE;
    cursor: pointer; */
    width: 25px;
}

.current_pageName {
    cursor: default;
    border: 1px solid #eee;
    color: #ddd;
}


.current_page_number { /* background: #26B;
    color: white;
    border: solid 1px #eee;
    cursor: default; */
    color: #FFF;
    background-color: #a6a7ab;
    width: 25px;
}

#jpagebar a.current_pageName,#jpagebar a.current_page_number {
    color: #FF6600;
    font-weight:bold;   
    border:none;
    background: none;
}


.totalpage_number {
    color: #2278db;
    border: 1px solid #5A9D0F;
    height: 25px;
    line-height: 25px;
    width: 60px;
    text-align: center;
    /* position:absolute;
    left:-65px; */
    margin-left: 5px;
}
/* 前台统一的分页样式 about pagebar -linlijun*/

.pagebar  a.current_pageName,#jpagebar  a.current_pageName {color:#999999;
border: 1px solid #999999;}
.pagebar  a.current_page_number,#jpagebar  a.current_page_number{
    color:#ffffff; background-color:#7cc064;}
.pagebar  a:hover, .pagebar a.on,#jpagebar  a:hover, #jpagebar a.on{ 
    background: #7cc064; color:#ffffff; background-color: #7cc064; }
.pagebar  a.current_pageName:hover{color:#999999;
border: 1px solid #999999; background:none;cursor: default;}



.input_ff{width:50px;height:25px;}
#pageNoText{text-align:center; margin:0 4px 0 5px;}
.pageTextBox,.goPage{display:inline-block; margin:0 0 0 20px;}

.pagebar .goBtn{margin:0 0 0 4px;padding:0 10px;color: #5A9D0F;height:25px;line-height:25px;
    border: 1px solid #5A9D0F;background:none;border-radius:0;}
.pagebar .goBtn:hover{color:#ffffff;background:#7cc064}















  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值