jquery.pager.js分页实现详解
网络编程 2021-07-04 15:51www.168986.cn编程入门
这篇文章主要为大家详细介绍了jquery.pager.js分页的实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了jquery.pager.js分页实现代码,供大家参考,具体内容如下
jquery.pager.js
/ jQuery pager plugin Version 1.0 (12/22/2008) @requires jQuery v1.2.6 or later Example at: http://jonpauldavies.github./JQuery/Pager/PagerDemo.html Copyright (c) 2008-2009 Jon Paul Davies Dual licensed under the MIT and GPL licenses: http://.opensource./licenses/mit-license.php http://.gnu./licenses/gpl.html Read the related blog post and contact the author at http://.j-dee./2008/12/22/jquery-pager-plugin/ This version is far from perfect and doesn't manage it's own state, therefore contributions are more than wele! Usage: .pager({ pagenumber: 1, pagecount: 15, buttonClickCallback: PagerClickTest }); Where pagenumber is the visible page number pagecount is the total number of pages to display buttonClickCallback is the method to fire when a pager button is clicked. buttonClickCallback signiture is PagerClickTest = function(pageclickednumber) Where pageclickednumber is the number of the page clicked in the control. The included Pager.CSS file is a dependancy but can obviously tweaked to your wishes Tested in IE6 IE7 Firefox & Safari. Any browser strangeness, please report. / (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 = $('<ul class="pages"></ul>'); // add in the previous and next buttons $pager.append(renderButton('第一页', pagenumber, pagecount, buttonClickCallback)).append(renderButton('上一页', pagenumber, pagecount, buttonClickCallback)); // pager currently only handles 5 viewable pages ( could be easily parameterized, maybe in next version ) so handle edge cases var startPoint = 1; var endPoint = 5; if (pagenumber > 2) { startPoint = pagenumber - 2; endPoint = pagenumber + 2; } if (endPoint > pagecount) { startPoint = pagecount - 3; endPoint = pagecount; } if (startPoint < 1) { startPoint = 1; } // loop thru visible pages and render buttons for (var page = startPoint; page <= endPoint; page++) { var currentButton = $('<li class="page-number">' + (page) + '</li>'); 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('下一页', pagenumber, pagecount, buttonClickCallback)).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 = $('<li class="pgNext">' + buttonLabel + '</li>'); var destPage = 1; // work out destination page for required button type switch (buttonLabel) { case "第一页": destPage = 1; break; case "上一页": destPage = pagenumber - 1; break; case "下一页": destPage = pagenumber + 1; break; case "尾页": destPage = pagecount; break; } // disable and 'grey' out buttons if not needed. if (buttonLabel == "第一页" || 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);
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 #c; text-decoration:none; margin:0 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 #003f7e; color:#000; font-weight:700; background-color:#eee; }
html代码
<html xmlns="http://.w3./1999/xhtml"> <head> <title>jQuery.pager.js Test</title> <link href="Pager.css" rel="stylesheet" type="text/css" /> <script src="jquery-1.2.6.js" type="text/javascript"></script> <script src="jquery.pager.js" type="text/javascript"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#pager").pager({ pagenumber: 1, pagecount: 15, buttonClickCallback: PageClick }); }); PageClick = function(pageclickednumber) { $("#pager").pager({ pagenumber: pageclickednumber, pagecount: 15, buttonClickCallback: PageClick }); $("#result").html("Clicked Page " + pageclickednumber); } </script> </head> <body> <h1 id="result">Click the pager below.</h1> <div id="pager" ></div> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程