페이지 스크롤에 더 많은 정보를로드하는 자바 스크립트 스크립트가 있습니다. 문제는 내가 아래로 스크롤하면 스크립트가 두 번 실행되고 동일한 결과가 두 번 이상이라는 것입니다.
아래로 스크롤 할 때마다 스크립트를 한 번 실행하고 매번 두 번 이상 실행하지 않으려 고합니다.
다음은 스크립트입니다.
$(window).scroll(function(){
var lastID = $('.load-more').attr('lastid');
if ($(window).scrollTop() == $(document).height() - $(window).height() && lastID != 0){
$.ajax({
type:'POST',
url:'getdata.php',
data:'id='+lastID,
beforeSend:function(html){
$('.load-more').show();
},
success:function(html){
$('.load-more').remove();
$('#list').append(html);
}
});
}
});
이 시도
var counter = 0;
$(window).scroll(function(){
var lastID = $('.load-more').attr('lastid');
if ($(window).scrollTop() == $(document).height() - $(window).height() && lastID != 0 && counter < 1){
counter++;
$.ajax({
type:'POST',
url:'getdata.php',
data:'id='+lastID,
beforeSend:function(html){
$('.load-more').show();
},
success:function(html){
// reset counter to 0 after you get your results
counter = 0;
$('.load-more').remove();
$('#list').append(html);
}
});
}
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다