2014-03-31 66 views
1

我想使用無限滾動,但是當我向下滾動時沒有任何事情發生。這是我當前的頁碼的外觀:實現無限滾動

<ul class="elgg-pagination"> 
    <li class="elgg-state-disabled"><span>« Previous</span></li> 
    <li class="elgg-state-selected"><span>1</span></li> 
    <li><a href="http://siteexample.com/casting?offset=10">2</a></li> 
    <li><a href="http://siteexample.com/casting?offset=20">3</a></li> 
    <li><a href="http://siteexample.com/casting?offset=30">4</a></li> 
    <li><a href="http://siteexample.com/casting?offset=40">5</a></li> 
    <li><a href="http://siteexample.com/casting?offset=50">6</a></li> 
    <li><a href="http://siteexample.com/casting?offset=10">Next »</a></li> 
</ul> 

這是我的JavaScript的樣子:

$(window).scroll(function(){ 
var mostOfTheWayDown = ($(document).height() - $(window).height()) * 9/10; 
if ($(window).scrollTop() >= mostOfTheWayDown){ 
$container.infinitescroll({ 

    navSelector : $('a',find('.elgg-state-selected')), // selector for the paged  navigation 
    nextSelector : $('a',find('.elgg-state-selected').next('li').not('.elgg-state-disabled')), // selector for the NEXT link (to page 2) 
    itemSelector : '.item1',  // selector for all items you'll retrieve 
    loading: { 
    finishedMsg: 'No more pages to load.', 
    img: 'http://i.imgur.com/6RMhx.gif' 
} 
    }, 
    // trigger Masonry as a callback 
    function(newElements) { 
    // hide new items while they are loading 
    var $newElems = $(newElements).css({ opacity: 0 }); 
    // ensure that images load before adding to masonry layout 
    $newElems.imagesLoaded(function(){ 
     // show elems now they're ready 
     $newElems.animate({ opacity: 1 }); 
     $container.masonry('appended', $newElems, true); 
    }); 
    } 
); 
    } 
+0

你打開控制檯,並檢查錯誤 – adeneo

+0

類型錯誤:找到(...)接下來是不是一個函數 – user3479684

+0

然後你知道問題是什麼,沒有像這樣的選擇器內部找到。 – adeneo

回答

0

我建議這個插件,不要浪費你的時間重新發明輪子,享受的jQuery的迷死人!

http://www.infinite-scroll.com/

// infinitescroll() is called on the element that surrounds 
// the items you will be loading more of 
    $('#content').infinitescroll({ 

    navSelector : "div.navigation",    
        // selector for the paged navigation (it will be hidden) 
    nextSelector : "div.navigation a:first",  
        // selector for the NEXT link (to page 2) 
    itemSelector : "#content div.post"   
        // selector for all items you'll retrieve 
    }); 

,你也可以試試這個:

http://airbnb.github.io/infinity/demo-on.html