jquery.pager.js分頁(yè)實(shí)現(xiàn)詳解
本文實(shí)例為大家分享了jquery.pager.js分頁(yè)實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
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>
<h1 id="result">Click the pager below.</h1>
<div id="pager" ></div>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jquery.pager.js實(shí)現(xiàn)分頁(yè)效果
- 詳解MVC如何使用開源分頁(yè)插件(shenniu.pager.js)
- 用jQuery中的ajax分頁(yè)實(shí)現(xiàn)代碼
- JQuery+Ajax無(wú)刷新分頁(yè)的實(shí)例代碼
- 基于jQuery的實(shí)現(xiàn)簡(jiǎn)單的分頁(yè)控件
- 基于JQuery的Pager分頁(yè)器實(shí)現(xiàn)代碼
- jQuery中jqGrid分頁(yè)實(shí)現(xiàn)代碼
- jQuery DataTables插件自定義Ajax分頁(yè)實(shí)例解析
- jquery pagination插件實(shí)現(xiàn)無(wú)刷新分頁(yè)代碼
- jquery向上向下取整適合分頁(yè)查詢
- jQuery pager.js 插件動(dòng)態(tài)分頁(yè)功能實(shí)例分析
相關(guān)文章
jquery庫(kù)或JS文件在eclipse下報(bào)錯(cuò)問(wèn)題解決方法
在工程中導(dǎo)入jquery-1.7.1之后一直有一個(gè)紅叉叉,雖然不會(huì)影響程序功能,但是看著非常不舒服,下面有個(gè)不錯(cuò)的解決方法,大家可以嘗試下2014-04-04
基于JQuery.timer插件實(shí)現(xiàn)一個(gè)計(jì)時(shí)器
基于JQuery.timer插件實(shí)現(xiàn)一個(gè)計(jì)時(shí)器,需要的朋友可以參考下。2010-04-04
JavaScript實(shí)現(xiàn)的彈出遮罩層特效經(jīng)典示例【基于jQuery】
這篇文章主要介紹了JavaScript實(shí)現(xiàn)的彈出遮罩層特效,結(jié)合實(shí)例形式分析了基于jQuery實(shí)現(xiàn)的頁(yè)面元素與屬性動(dòng)態(tài)操作相關(guān)使用技巧,需要的朋友可以參考下2019-07-07
jquery+json 通用三級(jí)聯(lián)動(dòng)下拉列表
用Jquery實(shí)現(xiàn),原始代碼只支持IE,這里我改了一下,我的代碼里面有三個(gè)版本的實(shí)現(xiàn)2010-04-04
jquery+css實(shí)現(xiàn)的紅色線條橫向二級(jí)菜單效果
這篇文章主要介紹了jquery+css實(shí)現(xiàn)的紅色線條橫向二級(jí)菜單效果,界面美觀大方,簡(jiǎn)潔實(shí)用,通過(guò)jquery遍歷及切換頁(yè)面元素實(shí)現(xiàn)這一功能,需要的朋友可以參考下2015-08-08
easyui Droppable組件實(shí)現(xiàn)放置特效
droppable和draggable有類似的地方,不過(guò)區(qū)別點(diǎn)在于前者著重于將元素放進(jìn)某個(gè)容器中,而后者則著重于可拖拽(雖然可能一些效果兩者都可以實(shí)現(xiàn))。而且通過(guò)查看easyloader源碼可知道,droppable并不依賴于draggable。2015-08-08
jQuery中實(shí)現(xiàn)動(dòng)畫效果的基本操作介紹
本篇文章小編將為大家介紹,在jQuery中實(shí)現(xiàn)動(dòng)畫效果的基本操作介紹,需要的朋友可以參考一下2013-04-04
JQuery中DOM加載與事件執(zhí)行實(shí)例分析
這篇文章主要介紹了JQuery中DOM加載與事件執(zhí)行,實(shí)例分析了jQuery中DOM加載及事件執(zhí)行的原理與實(shí)現(xiàn)方法,并補(bǔ)充說(shuō)明了windows.onload方法和$(document).ready()方法的區(qū)別,需要的朋友可以參考下2015-06-06

