테스트 사이트 - 개발 중인 베타 버전입니다

반응형페이징!

· 10년 전 · 1469 · 14

반응형웹만들때 페이징때문에 고민하셨죠? 간편하게 제가 하나만들었습니다ㅎ

 

[code]

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.js"></script> 

<style type="text/css">

.paging{color:#555;padding:0;}

.paging li{list-style:none;}

.paging li{line-height:25px; cursor:default; text-align:center; width:25px; height:25px; display:inline-block; font-size: 12px; font-weight:bold; color:#333;}

.paging .pg:hover{cursor:pointer; text-decoration: underline}

.paging .current{color:#FF3636; cursor:default !important; text-decoration:none !important;}

.first, .pre, .next, .last{color:#888 !important;}

.first, .last{letter-spacing:-3px;}

.active{color:#333 !important; cursor:pointer !important;}

</style>

 

<script type="text/javascript">

 

window.onload = function() {

var n = 0,

    c  = 35 , // 전체페이지(35페이지)

    w = 27 , //페이지표시 1개의 가로사이즈값

    current = 1; // 현재페이지(1페이지)

 

/* 페이지클릭시 */

$(document).delegate('.pg','click',function(e){

current = parseInt($(this).text());

$('.pg').removeClass('current');$(this).addClass('current'); // 페이지 클릭시 추가되는 클래스(current)

});

 

/* 맨앞, 앞, 뒤, 맨뒤 버튼 클릭시 */

$(document).delegate('.first, .pre, .next, .last','click',function(e){

var x = Math.floor((parseInt($('.paging').css('width'))-w*4)/w);

if(x > 10){x=10;}

if(n >= 1){

if($(this).is('.first')){current=1;paging();}

if($(this).is('.pre')){current=n-x+1;paging();}

if(c > n+x){

if($(this).is('.next')){current=n+x+1;paging();}

if($(this).is('.last')){current=c;paging();}

}

});

    

/* 맨앞, 앞, 뒤, 맨뒤 버튼 클릭시 */

function paging(){

var page='<li class="first"><<</li><li class="pre"><</li>';

var x = Math.floor((parseInt($('.paging').css('width'))-w*4)/w);

if(x > 10){x=10;}

n = Math.floor(current/x);

if(n == current/x){n = n*x-x;}else{n = n*x}

for(var i=1; i <= x; i++ ){

if(current == i+n){

page += '<li class="pg current">'+(i+n)+'</li>';

}else{

page += '<li class="pg">'+(i+n)+'</li>';}

if(i == x || i == 10 || i+n == c){$('.paging').html(page+'<li class="next">></li><li class="last">>></li>');

if(n > 1){$('.first, .pre').addClass('active');}  // 맨앞, 앞 활성화시 추가되는 클래스(active)

if(c > n+x){$('.next, .last').addClass('active');}  // 뒤, 맨뒤 버튼 활성화시 추가되는 클래스(active)

break}}

}

 

paging() //웹페이지 불러올시 반응형페이징 함수 작동

 

window.onresize = function(){paging()}  //브라우저 사이즈 조절시 반응형페이징 함수 작동

}

 

</script>

 

<ul class="paging"></ul> <!-- 반응형페이징을 불러올 위치 -->

 

[/code]

군인신분으로 사이버지식정보방에서 만든거라 보안상 파일업로드가 안되므로 글로 올리는점 양해바랍니다.

 

http://sir.co.kr/bbs/board.php?bo_table=cm_free&wr_id=1113337

 

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 14개

얼마든지요^^ㅎ;
오~좋은 것 같아요~잘 쓰겠습니다~
10년 전
잘 쓰겠습니다. 군인이신데 바쁜 와중에도 좋은 자료를 올려주셨네요.
28일에 전역했어요^^ㅋ;

게시글 목록

번호 제목
32341
32339
32326
32325
32322
32319
32318
32316
32315
32313
32312
32311
32310
32304
32303
32300
32293
32292
32291
32285
32284
32275
32271
32268
32265
32261
32258
32257
32255
32254
32253
32251
32250
32249
32247
32246
32245
32244
32243
32242
32241
32240
32239
32238
32237
32236
32232
32229
32228
32227
32217
32215
32214
32213
32211
32207
32196
32193
32192
32190
32188
32186
32184
32173
32172
32171
32167
32165
32163
32162
32158
32157
32155
32151
32149
32135
32132
32127
32125
32122
32120
32119
32117
32116
32115
32114
32112
32111
32109
32107
32104
32103
32102
32101
32094
32089
20404
31036
8279
8268