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

반응형페이징!

· 10년 전 · 1475 · 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개

그누보드에 연동할시 게시판스킨에서 <?php echo $write_pages; ?>와 기존 페이징 관련css를 모조리 지우신후에 원하는 위치에 저소스를 삽입하고

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

c = <?php echo $total_page?> , 로 수정해주시고

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

current = <?php echo $page ?>; 로 수정해주시면됩니다.

디자인은 알아서^^;
복무중에 귀한자료를 ^^.. 감사합니다. 그리고 남은 군복무 잘 마무리 하세요 ~
예^^...감사합니다;
그누보드에서 페이지에 링크거는법을깜빡했네요. 이걸추가시키면됩니다^^;
25번줄과 26번줄 구문 사이에 이스크립트를 추가시키면됩니다.

[code]
$(location).attr('href',<?php echo g5_bbs_url ?> + '/board.php?bo_table=' + <?php echo $bo_table ?> + '&page=' + current );
[/code]
우와...좋은 소스 고마워요. 잘 쓸게요.
근데, 대체 뭘 공부하면 이런 걸 짤 수 있죠? ㅎ
그냥...독학했습니다^^;
외국사이트돌아다니면서 소스도 한번씩 파헤쳐보고...ㅎ;
제가 반응형웹을 처음 접하게된게 아마 2013년때쯤이었을껍니다.. 그러다가 css로 반응형웹을 짜는기술도 있공...자유롭게 하는방법에선 자바스크립트가 짱이더라고요ㅎ;
오호, 3년만에 이런 성취를....대단하십니다. ^^
거기에 20개월 가까이 지금 군대에있습니다...ㅎ;
군생활 제대로 하셨네요. ㅎㅎ
10년 전
적용해야겟네요 ㅎ

게시글 목록

번호 제목
20318
20317
20316
20315
20314
20313
20312
20311
20310
20309
20308
20307
20306
20303
20302
20301
20300
20299
20298
20297
20296
20295
20294
20293
20292
8222
20291
20290
20289
20288
20287
20286
20285
20284
20283
20282
20281
20280
20276
20275
20274
20273
8216
20272
20271
20270
20269
20268
20267
20265
20264
20263
20262
20261
20259
20258
20257
20256
20255
20254
20253
20252
20251
20250
20249
31028
20248
20247
20246
8215
20245
20244
20243
20242
20241
20240
20239
20238
20237
20236
20235
20234
20233
8197
20232
20231
20230
20229
20228
20227
20225
20224
20223
20222
20221
20220
20219
20218
20217
20216