基于jquery.page.js實(shí)現(xiàn)分頁(yè)效果
基于jquery.page.js的一款簡(jiǎn)單的分頁(yè)效果,供大家參考,具體內(nèi)容如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>簡(jiǎn)單的jQuery分頁(yè)插件</title>
<style>
*{ margin:0; padding:0; list-style:none;}
a{ text-decoration:none;}
a:hover{ text-decoration:none;}
.tcdPageCode{padding: 15px 20px;text-align: left;color: #ccc;text-align:center;}
.tcdPageCode a{display: inline-block;color: #428bca;display: inline-block;height: 25px; line-height: 25px; padding: 0 10px;border: 1px solid #ddd; margin: 0 2px;border-radius: 4px;vertical-align: middle;}
.tcdPageCode a:hover{text-decoration: none;border: 1px solid #428bca;}
.tcdPageCode span.current{display: inline-block;height: 25px;line-height: 25px;padding: 0 10px;margin: 0 2px;color: #fff;background-color: #428bca; border: 1px solid #428bca;border-radius: 4px;vertical-align: middle;}
.tcdPageCode span.disabled{ display: inline-block;height: 25px;line-height: 25px;padding: 0 10px;margin: 0 2px; color: #bfbfbf;background: #f2f2f2;border: 1px solid #bfbfbf;border-radius: 4px;vertical-align: middle;}
</style>
</head>
<body>
<br><br><br>
<div class="tcdPageCode"></div>
<center><pre><br>
</pre></center>
<script src="js/jquery-1.8.3.min.js"></script>
<script src="js/jquery.page.js"></script>
<script>
$(".tcdPageCode").createPage({
pageCount:100,
current:1,
backFn:function(p){
console.log(p);
}
});
</script>
</body>
</html>
調(diào)用方法如下:
$(".tcdPageCode").createPage({
pageCount:10,
current:1,
backFn:function(p){
//單擊回調(diào)方法,p是當(dāng)前頁(yè)碼
}
});
pageCount:總頁(yè)數(shù)
current:當(dāng)前頁(yè)
以下是jquery.page.js源代碼:
(function($){
var ms = {
init:function(obj,args){
return (function(){
ms.fillHtml(obj,args);
ms.bindEvent(obj,args);
})();
},
//填充html
fillHtml:function(obj,args){
return (function(){
obj.empty();
//上一頁(yè)
if(args.current > 1){
obj.append('<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="prevPage">上一頁(yè)</a>');
}else{
obj.remove('.prevPage');
obj.append('<span class="disabled">上一頁(yè)</span>');
}
//中間頁(yè)碼
if(args.current != 1 && args.current >= 4 && args.pageCount != 4){
obj.append('<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tcdNumber">'+1+'</a>');
}
if(args.current-2 > 2 && args.current <= args.pageCount && args.pageCount > 5){
obj.append('<span>...</span>');
}
var start = args.current -2,end = args.current+2;
if((start > 1 && args.current < 4)||args.current == 1){
end++;
}
if(args.current > args.pageCount-4 && args.current >= args.pageCount){
start--;
}
for (;start <= end; start++) {
if(start <= args.pageCount && start >= 1){
if(start != args.current){
obj.append('<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tcdNumber">'+ start +'</a>');
}else{
obj.append('<span class="current">'+ start +'</span>');
}
}
}
if(args.current + 2 < args.pageCount - 1 && args.current >= 1 && args.pageCount > 5){
obj.append('<span>...</span>');
}
if(args.current != args.pageCount && args.current < args.pageCount -2 && args.pageCount != 4){
obj.append('<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tcdNumber">'+args.pageCount+'</a>');
}
//下一頁(yè)
if(args.current < args.pageCount){
obj.append('<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="nextPage">下一頁(yè)</a>');
}else{
obj.remove('.nextPage');
obj.append('<span class="disabled">下一頁(yè)</span>');
}
})();
},
//綁定事件
bindEvent:function(obj,args){
return (function(){
obj.on("click","a.tcdNumber",function(){
var current = parseInt($(this).text());
ms.fillHtml(obj,{"current":current,"pageCount":args.pageCount});
if(typeof(args.backFn)=="function"){
args.backFn(current);
}
});
//上一頁(yè)
obj.on("click","a.prevPage",function(){
var current = parseInt(obj.children("span.current").text());
ms.fillHtml(obj,{"current":current-1,"pageCount":args.pageCount});
if(typeof(args.backFn)=="function"){
args.backFn(current-1);
}
});
//下一頁(yè)
obj.on("click","a.nextPage",function(){
var current = parseInt(obj.children("span.current").text());
ms.fillHtml(obj,{"current":current+1,"pageCount":args.pageCount});
if(typeof(args.backFn)=="function"){
args.backFn(current+1);
}
});
})();
}
}
$.fn.createPage = function(options){
var args = $.extend({
pageCount : 10,
current : 1,
backFn : function(){}
},options);
ms.init(this,args);
}
})(jQuery);
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 用jQuery中的ajax分頁(yè)實(shí)現(xiàn)代碼
- jQuery scroll事件實(shí)現(xiàn)監(jiān)控滾動(dòng)條分頁(yè)示例
- JQuery+Ajax無刷新分頁(yè)的實(shí)例代碼
- 基于jQuery的實(shí)現(xiàn)簡(jiǎn)單的分頁(yè)控件
- 基于JQuery的Pager分頁(yè)器實(shí)現(xiàn)代碼
- jQuery中jqGrid分頁(yè)實(shí)現(xiàn)代碼
- jQuery EasyUI API 中文文檔 - Pagination分頁(yè)
- jQuery Pagination Ajax分頁(yè)插件(分頁(yè)切換時(shí)無刷新與延遲)中文翻譯版
- jQuery EasyUI datagrid實(shí)現(xiàn)本地分頁(yè)的方法
- jQuery DataTables插件自定義Ajax分頁(yè)實(shí)例解析
相關(guān)文章
jQuery讀取和設(shè)定KindEditor值的方法
這篇文章主要介紹了jQuery讀取和設(shè)定KindEditor值的方法,大家參考使用吧2013-11-11
JQuery與iframe交互實(shí)現(xiàn)代碼
JQuery與iframe交互實(shí)現(xiàn)代碼2009-12-12
jQuery選擇器源碼解讀(四):tokenize方法的Expr.preFilter
這篇文章主要介紹了jQuery選擇器源碼解讀(四):tokenize方法的Expr.preFilter,本文用詳細(xì)的注釋解讀了tokenize方法的Expr.preFilter的實(shí)現(xiàn)源碼,需要的朋友可以參考下2015-03-03
Jquery選擇子控件"大于號(hào)"和" "區(qū)別介紹及使用示例
Jquery選擇子控件”>“:在給定的父元素下匹配所有的子元素;另一個(gè)就是在給定的祖先元素下匹配所有的后代元素,具體概述及使用示例如下,感興趣的朋友可以參考下哈2013-06-06
jquery 為a標(biāo)簽綁定click事件示例代碼
jquery 為a標(biāo)簽綁定click事件,當(dāng)被點(diǎn)擊時(shí)執(zhí)行一些動(dòng)作,示例代碼如下,需要的朋友可以參考參考2014-06-06
jQuery 頁(yè)面 Mask實(shí)現(xiàn)代碼
何為頁(yè)面 Mask (遮罩)?看過 jQuery 的 Lightbox 插件的一定不會(huì)陌生。就是在頁(yè)面上建一個(gè)透明層遮蓋住頁(yè)面的全部?jī)?nèi)部。2010-01-01

