2013-06-01 4 views
0
$(function() { 
    $(window).scroll(function(){ 
    checkY(); 
    }); 
$('.post').last().after('<div class="newPost" />'); 
    var hrefArray = [],//array global 
    hrefs = $('.paging a[href*="/t"]').not('.paging a[href*="/t"] > img'); 
for(var i=0;i<hrefs.length;i++) { 
    var hreflink = $(hrefs[i]).attr('href'); 
    hrefArray.push(hreflink); 
    } 
    hrefArray.pop(); 
    var postedLast = $('.post').last().position().top + $('.post').last().outerHeight(); 

function checkY(){ 
if(hrefArray.length > 1) { 
    if($(window).scrollTop() > postedLast){ 
     var url = hrefArray.shift(); 
      $('.newPost').html('<img class="loadingImg" src="http://i79.servimg.com/u/f79/17/83/35/07/loadin10.gif"/>'); 
setTimeout(function() { 
    $('.loadingImg').remove(); 
    $('.newPost').last().load(url+" .post",function() { 
    //THIS LINE BELOW IS THE PROBLEM 
    $('.newPost').last().after('<div class="newPost" />'); 
    postedLast = $('.post').last().position().top + 
        $('.post').last().outerHeight(); 
    }); 
},3000); 
    } 
} 
} 
    window.onLoad = checkY(); 
}); 

위의 코드는 무한 스크롤의 모의 객체입니다. 내 문제는 그 라인을 계속해서 계속 덧붙여 두는 것이다. 한 번 추가하는 방법이 있습니까? 나는 이것을 위해 거의 모든 것을 시도해 왔고, 지금까지 그렇게 노력하지 않았다. 또한이 대신에 방법이 있습니다요소를 여러 번 추가하는 무한 스크롤 문제

$('.post').last().position().top + $('.post').last().outerHeight(); 

시간에로드하고 싶지 않은 것 같습니다. 엘리먼트가 화면 하단에 오면 기능을 수행합니다. 이 때문에 - if($(window).scrollTop() > postedLast){ 다른 방법이 있나요? 따라서 화면 맨 위에있는 대신 화면 맨 아래에서 작동합니까? 확인이 밖으로

답변

0

(가시 끝) :

http://www.jquery4u.com/tutorials/jquery-infinite-scrolling-demos/

난 당신이 아마 바퀴를 재발견 할 필요없이 이미 당신이 뭘 하려는지 할 좋은 오픈 소스 플러그인을 활용할 수 있다고 생각합니다, 또는 두 번째 예에서이 스 니펫을 사용할 수 있습니다 (간단하면서도 효과적이었습니다). 여기에서 복사하여 붙여 넣으려는 것입니다 :