本文實(shí)例為大家分享了jquery.pager.js分頁(yè)實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、馬關(guān)網(wǎng)絡(luò)推廣、小程序開(kāi)發(fā)、馬關(guān)網(wǎng)絡(luò)營(yíng)銷、馬關(guān)企業(yè)策劃、馬關(guān)品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供馬關(guān)建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:muchs.cn
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('第一頁(yè)', pagenumber, pagecount, buttonClickCallback)).append(renderButton('上一頁(yè)', 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('下一頁(yè)', pagenumber, pagecount, buttonClickCallback)).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 "第一頁(yè)": destPage = 1; break; case "上一頁(yè)": destPage = pagenumber - 1; break; case "下一頁(yè)": destPage = pagenumber + 1; break; case "尾頁(yè)": destPage = pagecount; break; } // disable and 'grey' out buttons if not needed. if (buttonLabel == "第一頁(yè)" || 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);
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: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://www.w3.org/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> <h2 id="result">Click the pager below.</h2> <div id="pager" ></div> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)站標(biāo)題:jquery.pager.js分頁(yè)實(shí)現(xiàn)詳解
瀏覽路徑:http://muchs.cn/article14/pidcge.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、網(wǎng)站制作、微信公眾號(hào)、域名注冊(cè)、商城網(wǎng)站、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)