您的修复发生在无限滚动脚本之外。您应该将其更改为包含它,如下所示:
// other stuff up here
}, function( newElements ) {
var $newElems = $(newElements).css({
opacity: 0
});
$newElems.imagesLoaded(function () {
$newElems.animate({
opacity: 1
});
$container.masonry('appended', $newElems, true);
});
/* repair video players*/
$newElems.find('.video').each(function(){
var audioID = $(this).attr("id");
var $videoPost = $(this);
$.ajax({
url: '/api/read/json?id=' + audioID,
dataType: 'jsonp',
timeout: 10000,
success: function(data){
$videoPost.html(data.posts[0]["video-player"]);
}
});
});
/* repair audio players*/
$newElems.find('.player').each(function(){
var audioID = $(this).attr("id");
var $audioPost = $(this);
$.ajax({
url: '/api/read/json?id=' + audioID,
dataType: 'jsonp',
timeout: 10000,
success: function(data){
$audioPost.html(data.posts[0]["audio-player"]);
}
});
});
});
我正在使用$newElems.find()
,因为我们只想加载页面上的新帖子。如果您这样做$('.video')
,您将浏览所有帖子,包括已经加载的帖子。