jquery.pager.js實(shí)現(xiàn)分頁(yè)效果
本文實(shí)例為大家分享了jquery.pager.js實(shí)現(xiàn)分頁(yè)的具體代碼,供大家參考,具體內(nèi)容如下
1.html
<link href="/stylesheets/Pager.css" rel="stylesheet" type="text/css"/> <script src="/javascripts/web/jquery.pager.js" type="text/javascript"></script> <body> <div id="pager"> <div id="countPage" style="display:none">{{maxPage}}</div> <div id="title" style="display:none">{{title}}</div> <div id="nowPage" style="display:none">{{page}}</div> </div> </body> <script type="text/javascript"> var title =jQuery("#title").text() ; var pageCount =parseInt(jQuery("#countPage").text()) ; var nowPage=parseInt(jQuery("#nowPage").text()); jQuery(function(){ $("#pager").pager({ pagenumber: nowPage, pagecount: pageCount, buttonClickCallback: PageClick });//pagenumber:當(dāng)前頁(yè),pagecount:總頁(yè)數(shù) }); PageClick = function(pageclickednumber) { $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pageCount, buttonClickCallback: PageClick }); window.location.href = "/article/search/"+title+"/"+pageclickednumber; } </script>
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-color:#eee;*/ background: #3c90d9 none repeat scroll 0 0; } #pager{margin-left: 290px;}
3.jquery.pager.js
/* * jQuery pager plugin * Version 1.0 (12/22/2008) * @requires jQuery v1.2.6 or later * * Example at: http://jonpauldavies.github.com/JQuery/Pager/PagerDemo.html * * Copyright (c) 2008-2009 Jon Paul Davies * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Read the related blog post and contact the author at http://www.j-dee.com/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 welcome! * * 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('first', pagenumber, pagecount, buttonClickCallback)).append(renderButton('prev', pagenumber, pagecount, buttonClickCallback)); $pager.append(renderButton('上一頁(yè)', 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 && pagenumber<pagecount-1) { startPoint = pagenumber - 2; endPoint = pagenumber + 2; } if(pagenumber>pagecount-2&& pagenumber<pagecount+1){ startPoint = pagecount - 4; endPoint = pagecount; } if (endPoint > 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 = $('<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('next', pagenumber, pagecount, buttonClickCallback)).append(renderButton('last', pagenumber, pagecount, buttonClickCallback)); $pager.append(renderButton('下一頁(yè)', 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 "first": destPage = 1; break; case "上一頁(yè)": destPage = pagenumber - 1; break; case "下一頁(yè)": destPage = pagenumber + 1; break; case "last": destPage = pagecount; break; } // disable and 'grey' out buttons if not needed. if (buttonLabel == "first" || buttonLabel == "上一頁(yè)") { 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);
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JQuery Dialog(JS 模態(tài)窗口,可拖拽的DIV)
JQuery Dialog(JS模態(tài)窗口,可拖拽的DIV) 效果實(shí)現(xiàn)代碼2010-02-02讓jQuery Mobile不顯示討厭loading界面的方法
jQuery Mobile總是顯示討厭的loading界面,下面有個(gè)不錯(cuò)的解決方法,大家可以參考下2014-02-02jquery實(shí)現(xiàn)tr元素的上下移動(dòng)示例代碼
讓tr元素的上下移動(dòng)的方法有很多,本文為大家介紹下使用jquery是實(shí)現(xiàn)的,感興趣的朋友可以參考下2013-12-12jquery+json實(shí)現(xiàn)的搜索加分頁(yè)效果
Javascript,json 實(shí)現(xiàn)的js 腳本搜索,加分頁(yè),附源碼2010-03-03Javascript jquery css 寫的簡(jiǎn)單進(jìn)度條控件
很多的時(shí)候用戶需要等待你“臃腫”的 Javascript 代碼處理完成(Web 2.0 的特色)。期間或許加入一個(gè)類似于進(jìn)度條的東西讓用戶有點(diǎn)“安慰”。這個(gè)東西實(shí)現(xiàn)起來(lái)并不復(fù)雜,無(wú)非就是獲得總的處理?xiàng)l目,然后獲得一個(gè)百分比,再顯示輸出。2008-03-03jQuery實(shí)現(xiàn)個(gè)性翻牌效果導(dǎo)航菜單的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)個(gè)性翻牌效果導(dǎo)航菜單的方法,實(shí)例分析了jQuery操作animate、css及鼠標(biāo)事件的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03jQuery中RadioButtonList的功能及用法實(shí)例介紹
RadioButtonList的使用想必大家都有所解除,本文為以示例的方式為大家詳細(xì)介紹下其功能及用法,感興趣的朋友可以參考下2013-08-08jQuery ajax 跨域插件jquery.xdomainrequest.min.js的使用方法
jQuery XDomainRequest 是一個(gè)利用 XDomainRequest 對(duì)象為 IE8、IE9 實(shí)現(xiàn)跨域資源共享(CORS - Cross Origin Resource Sharing)的 jQuery 插件2023-06-06