2014-06-10 49 views
0

我遇到了一個奇怪的問題與砌體。我使用無限滾動,當圖像加載時,它們被追加兩次。添加更多頁面後,我今天注意到了這個問題。我真的不確定是什麼導致它,但它的數字與我的jQuery代碼有關。我的代碼如下。圖像被添加兩次在砌體

(function(){ 

//masonry 
$(function() { 
    var container = document.querySelector('.post_container'); 
    var msnry = new Masonry(container, { 
     // options 
     itemSelector: '.post' 
    }); 
}); 

//images loaded 
var $container = $('.post_container'); 
$container.imagesLoaded(function(){ 
    $container.masonry({ 
     itemSelector : '.post' 

    }); 
}); 

$('.container').infinitescroll({ 
     navSelector : "div.pagination", 
     // selector for the paged navigation (it will be hidden) 
     nextSelector : "#next a", 
     // selector for the NEXT link (to page 2) 
     itemSelector : '.post', 
     // selector for all items you'll retrieve 

     loading: { 
      finished: undefined, 
      finishedMsg: "<em>Congratulations, you've reached the end of the internet.</em>", 
      msg: null, 
      msgText: "<em>Loading the next set of posts...</em>", 
      selector: null, 
      speed: 'fast', 
      start: undefined 
     } 
    }, //callback to make the all work together 
    function(newitems) { 
     $container.append(newitems); 
     imagesLoaded(newitems, function(){ 
      $container.masonry('appended', newitems); 
      $container.masonry('layout'); 
     }); 
    }); 

我已經加倍檢查我的html,甚至去刪除它,並檢查每個圖像一次。出於某種原因,插件會將圖像附加兩次。

回答

0

這可能與此

function(newitems) { 
    $container.append(newitems); // appending the same thing 
    imagesLoaded(newitems, function(){ 
     $container.masonry('appended', newitems); // appending the same thing 
     $container.masonry('layout'); 
    }); 
}); 

我不熟悉的磚石做的,但也許這就是爲什麼它追加了兩次。

+0

不,這是必要的,如果我沒有它會打破功能。 – London804