2014-04-03 98 views
1

我正試圖將砌體元素添加到現有的元素。在砌體初始化之前顯示停止項目

但是,我現在擁有的是this - 這些項目在磚石被初始化之前顯示,然後在第二秒後跳到位置。我想讓他們隱藏起來,直到他們到位。

這是我使用追加砌體項目代碼(無限滾動的插件內):

$container.append(data); 
$container.imagesLoaded(function() 
{ 
    $container.masonry('reloadItems').masonry(); 
}); 

這裏,它正在初始化:

$(document).ready(function() 
{ 
    $container = $('#container'); 
    // initialize the masonry instance 
    $container.imagesLoaded(function(){ 
     $container.masonry({ 
      columnWidth: 1, 
      itemSelector: '.item', 
      transitionDuration: 0 
     }); 
    }); 

    $('#container').scrollPagination({ 

     nop  : 36, // The number of posts per scroll to be loaded 
     offset : 0, // Initial offset, begins at 0 in this case 
     error : 'No More Posts!', // When the user reaches the end this is the message that is 
            // displayed. You can change this if you want. 
     delay : 500, // When you scroll down the posts will load after a delayed amount of time. 
         // This is mainly for usability concerns. You can alter this as you see fit 
     scroll : true // The main bit, if set to false posts will not load as the user scrolls. 
         // but will still load if the user clicks. 
    }); 
}); 

UPDATE

根據Josh的回答,我現在的代碼如下所示:

$container.append(data); 
$container.imagesLoaded(function() 
{ 
    $(".item").show(); 
    $container.masonry('reloadItems').masonry(); 
}); 

而且我已將<class='hide'>添加到商品代碼。

但是,當我刷新頁面時,現在沒有元素顯示出來。

+0

我的意思是讓你隱藏剛剛進入頁面的項目。 你隱藏了一切,所以它永遠不會顯示。另外,做一個$('。item')。removeClass('hide');而不是 – Josh

+0

這就是我遇到的問題 - 我如何僅僅提及新項目,而不是簡單地每個「」? – Sebastian

回答

0

讓他們加載引導程序隱藏 class set,並在磚石運行後將其刪除。

如果砌體需要它們是可見的以進行計算,那麼在加載時讓它們顯示在屏幕外。 Z-指數,瘋狂的位置等

更新 http://masonry.desandro.com/methods.html

於是我放棄在這裏的方法看一眼,如果沒有這種欺騙我談,我相信你可以的AJAX加載新項目,然後使用masonry.addItems(items)方法。

+0

感謝您的回覆 - 查看我的更新。 – Sebastian