栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

jquery.pager.js实现分页效果

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jquery.pager.js实现分页效果

本文实例为大家分享了jquery.pager.js实现分页的具体代码,供大家参考,具体内容如下

1.html


 



   
    {{maxPage}}
    {{title}}
    {{page}}
   

2.Pager.css

#pager ul.pages{
 display:block;
 border:none;
 text-transform:uppercase;
 font-size:10px;margin:10px 0 50px;padding:0;
}
#pager ul.pages li{
 list-style:none;
 float:left;
 border:1px solid #ccc;
 text-decoration:none;
 margin:-20px 5px 0 0;padding:5px;
}
#pager ul.pages li:hover{border:1px solid #003f7e; }
#pager ul.pages li.pgEmpty{
 border:1px solid #eee;
 color:#eee;
}
#pager ul.pages li.pgCurrent{
 border:1px solid #3c90d9;
 color: #fff;
 font-weight:700;
 
 background: #3c90d9 none repeat scroll 0 0;
}
#pager{margin-left: 290px;}

3.jquery.pager.js


(function($) {

 $.fn.pager = function(options) {

  var opts = $.extend({}, $.fn.pager.defaults, options);

  return this.each(function() {

   // empty out the destination element and then render out the pager with the supplied options
   $(this).empty().append(renderpager(parseInt(options.pagenumber), parseInt(options.pagecount), options.buttonClickCallback));

   // specify correct cursor activity
   $('.pages li').mouseover(function() { document.body.style.cursor = "pointer"; }).mouseout(function() { document.body.style.cursor = "auto"; });
  });
 };

 // render and return the pager with the supplied options
 function renderpager(pagenumber, pagecount, buttonClickCallback) {

  // setup $pager to hold render
  var $pager = $('
    '); // add in the previous and next buttons //$pager.append(renderButton('first', pagenumber, pagecount, buttonClickCallback)).append(renderButton('prev', pagenumber, pagecount, buttonClickCallback)); $pager.append(renderButton('上一页', pagenumber, pagecount, buttonClickCallback)); // pager currently only handles 10 viewable pages ( could be easily parameterized, maybe in next version ) so handle edge cases var startPoint = 1; //var endPoint = 9; var endPoint = 5; if (pagenumber > 4 && pagenumberpagecount-2&& pagenumber pagecount) { startPoint = pagecount - 8; endPoint = pagecount; } if (startPoint < 1) { startPoint = 1; } // loop thru visible pages and render buttons for (var page = startPoint; page <= endPoint; page++) { var currentButton = $('
  • ' + (page) + '
  • '); page == pagenumber ? currentButton.addClass('pgCurrent') : currentButton.click(function() { buttonClickCallback(this.firstChild.data); }); currentButton.appendTo($pager); } // render in the next and last buttons before returning the whole rendered control back. //$pager.append(renderButton('next', pagenumber, pagecount, buttonClickCallback)).append(renderButton('last', pagenumber, pagecount, buttonClickCallback)); $pager.append(renderButton('下一页', pagenumber, pagecount, buttonClickCallback)); return $pager; } // renders and returns a 'specialized' button, ie 'next', 'previous' etc. rather than a page number button function renderButton(buttonLabel, pagenumber, pagecount, buttonClickCallback) { var $Button = $('
  • ' + buttonLabel + '
  • '); var destPage = 1; // work out destination page for required button type switch (buttonLabel) { case "first": destPage = 1; break; case "上一页": destPage = pagenumber - 1; break; case "下一页": destPage = pagenumber + 1; break; case "last": destPage = pagecount; break; } // disable and 'grey' out buttons if not needed. if (buttonLabel == "first" || buttonLabel == "上一页") { pagenumber <= 1 ? $Button.addClass('pgEmpty') : $Button.click(function() { buttonClickCallback(destPage); }); } else { pagenumber >= pagecount ? $Button.addClass('pgEmpty') : $Button.click(function() { buttonClickCallback(destPage); }); } return $Button; } // pager defaults. hardly worth bothering with in this case but used as placeholder for expansion in the next version $.fn.pager.defaults = { pagenumber: 1, pagecount: 1 }; })(jQuery);

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

    转载请注明:文章转载自 www.mshxw.com
    本文地址:https://www.mshxw.com/it/74542.html
    我们一直用心在做
    关于我们 文章归档 网站地图 联系我们

    版权所有 (c)2021-2022 MSHXW.COM

    ICP备案号:晋ICP备2021003244-6号