-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage_turning.js
183 lines (172 loc) · 4.82 KB
/
page_turning.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
var len = $('.pageNum > a').length;
var lastIndex = 0;
var $_a = $('.pageNum > a');
var $_li = $('.pane > li');
var key_o = true;
var key_t = true;
// 显示上一页,下一页,函数
var show = function(){
if($_a.eq(0).css('font-weight') !== 'bold'){
$('.prev').html('上一页').css({'cursor':'pointer'});
key_o = true;
}
if($_a.eq(0).css('font-weight') == 'bold'){
$('.prev').html('').css({'cursor':'default'})
key_o = false;
}
if($_a.eq(len - 1).css('font-weight') !== 'bold'){
$('.next').html('下一页').css({'cursor':'pointer'});
key_t = true;
}
if($_a.eq(len - 1).css('font-weight') == 'bold'){
$('.next').html('').css({'cursor':'default'});
key_t = false;
}
}
//显示首尾页函数
var show_p_l = function(){
if($_a.eq(len-1).html() < 25){
$('.last').html('尾页').css({'cursor' : 'pointer'})
}
if($_a.eq(len - 1).html() == 25){
$('.last').html('').css({'cursor' : 'default'});
}
if($_a.eq(0).html() > 1){
console.log(1)
$('.first').html('首页').css({'cursor' : 'pointer'})
}
if($_a.eq(0).html() == 1){
$('.first').html('').css({' cursor' : 'default'});
}
}
// 点击下一页
$('.next').on('click',function(){
show();
if(key_t){
if(lastIndex < 2 || $_a.eq(lastIndex).html() > 22){
change_f_l('next');
show();
}else if($_a.eq(lastIndex).html() < 23){
change_m(1);
$_a.eq(lastIndex).html() > 22 ? $('.last').html('').css({'cursor':'default'}) : '';
}
}
show_p_l();
})
// 点击上一页
$('.prev').on('click',function(){
if(key_o){
console.log(lastIndex)
if(lastIndex < 2 || $_a.eq(lastIndex).html() > 23 || $_a.eq(lastIndex).html() < 4){
change_f_l('prev');
show();
}else if($_a.eq(lastIndex).html() < 24){
change_m(-1);
$_a.eq(lastIndex).html() < 4 ? $('.first').html('').css({'cursor':'default'}) : '';
}
}
})
//点击首页跳转
$('.first').on('click',function(){
for(var i = 0; i < len; i ++){
$_a.eq(i).html(i + 1);
}
change_f_l('first');
show();
show_p_l();
})
//点击尾页跳转
$('.last').on('click',function(){
for(var i = 0; i < len; i ++){
$_a.eq(i).html(21 + i);
}
change_f_l('last');
show();
show_p_l();
})
// 点击上下翻页,页数数字变换.
var change_f_l = function(direction){
$_a.removeClass('active');
$_li.removeClass('active');
if(direction == 'first' && direction){
lastIndex = 0;
}else if(direction == 'last' && direction){
lastIndex = len - 1;
}else if(direction == 'next' && direction){
lastIndex += 1;
}else if(direction == 'prev' && direction){
lastIndex -= 1;
}else if(direction == 4 && direction){
lastIndex = 4;
}else if(direction == 3 && direction){
lastIndex = 3;
}else if(direction == 2 && direction){
lastIndex = 2;
}else if(direction == 1 && direction){
lastIndex = 1;
}else if(direction == 0){
lastIndex = 0;
}
$_a.eq(lastIndex).addClass('active');
$_li.eq(lastIndex).addClass('active');
if(direction == 'last'){
lastIndex = 4;
}else if(direction == 'first'){
lastIndex = 0;
}
}
// 中间数字变换
var change_m = function(direction){
for(var i = 0; i < len; i ++){
var a = $_a.eq(i).html();
$_a.eq(i).html( (parseInt(a) + direction) );
}
}
//点击数字
$_li.on('click', function(){
if( ($_a.eq(0).html() == 1 && $_a.eq(1).html() == 2 ) && $(this).index() < 3 ){
change_f_l($(this).index());
}else if( ( $_a.eq(len-1).html() == 25 && $_a.eq(len-2).html() == 24 ) && $(this).index() >= 2 ){
change_f_l($(this).index());
}else if($(this).index() > 2 && $_a.eq(len-1).html() < 25){
if($_a.eq(len-1).html() != 24){
for(var i = 0; i < len; i ++){
var a = $_a.eq(i).html();
$_a.eq(i).html( parseInt(a) + ($(this).index() - 2) );
}
change_f_l(2);
}else if($_a.eq(len-1).html() == 24){
if($(this).index() == 4){
change_f_l(3);
}
if($(this).index() == 3){
change_f_l(2);
}
for(var i = 0; i < len; i ++){
var a = $_a.eq(i).html();
$_a.eq(i).html( parseInt(a) + ($(this).index() - lastIndex) );
}
}
}else if($(this).index() < 2 && $_a.eq(0).html() > 1){
if($_a.eq(0).html() != 2){
for(var i = 0; i < len; i ++){
var a = $_a.eq(i).html();
$_a.eq(i).html( parseInt(a) -(2 - $(this).index()) );
}
change_f_l(2);
}else if($_a.eq(0).html() == 2){
if($(this).index() == 1){
change_f_l(2);
}
if($(this).index() == 0){
change_f_l(1)
}
for(var i = 0; i < len; i ++){
var a = $_a.eq(i).html();
$_a.eq(i).html( parseInt(a) - ( lastIndex - $(this).index() ) );
}
}
}
show();
show_p_l();
})