모아보자 리스트 페이징 무한 스크롤 그누팁
리스트 페이징 무한 스크롤본문
list.skin.php <?php echo $write_pages; ?> 코드 아래쪽에 넣으면 됩니다.
<script>
var total_page = "<?php echo $total_page; ?>";
var now_page = "<?php echo $page; ?>";
var roll_page = now_page;
$(window).ready(function(){
console.log(now_page);
if(now_page != 1){
$(".topScroll").show();
}
if(roll_page != total_page){
$(".btmScroll").show();
}
});
$(window).scroll(function(){
var chkBtm = parseInt($(document).height()) - parseInt($(window).height());
if(chkBtm == $(window).scrollTop()){
roll_page++;
if(roll_page <= total_page){
callContent(roll_page,'append');
}
} else if($(window).scrollTop() == 0){
now_page--;
if(now_page > 0){
callContent(now_page,'prepend');
}
}
});
function callContent(a,b){
if(b=='append'){
$(".moreBtm").slideDown();
}else{
$(".moreTop").slideDown();
}
var url = "<?php echo G5_URL; ?>/<?php echo $bo_table; ?>?page="+a;
// 짧은주소 아닐때 var url = "<?=G5_BBS_URL?>/board.php?bo_table=<?=$bo_table?>&page="+a;
var tbody = "";
var thtml = "";
$.ajax({
type:"POST",
url:url,
dataType : "html",
success: function(html){
tbody = html.split('<tbody>');
thtml = tbody[1].split('</tbody>');
setTimeout(function() {
if(b=='append'){
$(".tbl_head01").find('tbody').append(thtml[0]);
}else{
$(".tbl_head01").find('tbody').prepend(thtml[0]);
}
$(".moreBar").slideUp();
if(now_page == 1){
$(".topScroll").slideUp();
}
if(roll_page == total_page){
$(".btmScroll").slideUp();
}
}, 1000); // 시간 0으로 넣으면 딜레이 없이 바로 로딩 됨
},
error: function(xhr, status, error) {
alert(error);
}
});
}
</script>