2014-06-10 5 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