基于jQuery封装的分页组件

2020-05-22 16:04:42易采站长站整理

由于项目需要实现分页效果,上jQuery插件库找了下,但是木有找到自己想要的效果,于是自己封装了个分页组件。

思路:

主要是初始化时基于原型建立的分页模板然后绑定动态事件并实现刷新DOM的分页效果。

1.page.init.css


@charset "utf=8";
*{
box-sizing: border-box;
padding: 0;
margin: 0;
}
.page{
font-size: 13px;
text-align: right;
}
.page .page_to{
display: inline-block;
max-width: 250px;
}
.page .page_to li{
display: inline-block;
width: auto;
height: auto;
border: 1px solid #ddd;
padding:5px 10px;
border-left-width: 0;
color: #323232;
cursor: pointer;
}
.page .page_to li.page_hide{
display: none;
}
.page .page_to li:hover{
color: #32C2CD;
background-color: #f4f4f4;
border-color: #DDDDDD;
}
.page .page_to li:first-child{
border-left-width: 1px;
}
.page .page_jump{
display: inline-block;
width: 180px;
}
.page .page_jump input.page_jump_input{
width: 52px;
height: 28px;
text-align: center;
text-decoration: none;
background-color: #fff;
border: 1px solid #ddd;
margin:0 4px;
}
.page .page_jump input.page_jump_btn{
display: inline-block;
padding: 7px 20px;
margin-left: 5px;
font-size: 14px;
font-weight: 400;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
border: 1px solid transparent;
border-radius: 4px;
background-color: #00BB9C;
color: #FFFFFF;
font-weight: bold;
}

2.pageInit.js


/**
* Created: 2017/6/20.
* author: Aaron
* address: http://www.cnblogs.com/aaron-pan/
*/
(function($,window,undefined){

var curPage='',
//跳转是否有值
jumpVal='',
//从DOM中重新获取数据总数/总页数
lists='',
totals='',
//是否返回值
isTrue=false;

var Page=function(opts){
this.settings= $.extend({},Page.defaults,opts);
curPage=this.settings.initPage;
totals=this.settings.totalPages;
jumpVal=this.settings.inputVal;
this.init();
};

//默认配置
Page.defaults={
container:'.page',
setPos:'body',
totalPages:null,
totalLists:null,
initPage:1,
inputVal:1,
callBack:null
};

Page.prototype={
init:function(){
this.create();
},
create:function(){
var _template='<div class="page">'+