获取tumblr like按钮以使用无限滚动

时间:2014-03-10 17:40:00

标签: javascript tumblr infinite-scroll social-media-like

我正试图让tumblr like按钮无限滚动。

以下是我的代码不起作用。

之后是一个有效的代码。

我不熟悉Javascript所以我不确定如何将它们网格化以使其正常工作

function( newElements ) {
    var $newElems = $(newElements);
    $newElems.hide();
    $newElems.imagesLoaded(function(){
        $wall.masonry( 'appended', $newElems,{isAnimated: false}, function() {
            $newElems.fadeIn('fast');
        });
    });
    }); 
$('#posts').show(0);
});

这里有一个有效的

function(newElements){
    var $newElems = $(newElements).css("opacity","0").css("pointer-events","none");
    $('.photoset-grid').photosetGrid({highresLinks: true,rel: $('.photoset-grid').attr('data-id'),gutter: '5px',onComplete: function(){}});
    $('.photoset-grid,.lightbox').each(function() {
        $(this).magnificPopup({delegate: 'a',type: 'image',gallery:{enabled:true},removalDelay: 200,mainClass: 'mfp-fade'});
    });
    var $newElemsIDs = $newElems.map(function (){return this.id;}).get();
    $newElems.imagesLoaded(function(){
        $newElems.css("opacity","1").css("pointer-events","auto");
        $K.masonry('appended',$newElems,true);
        console.log($newElems,$newElemsIDs);
        Tumblr.LikeButton.get_status_by_post_ids($newElemsIDs);
    });
});

感谢您的帮助。

编辑:我的完整代码

$(window).load(function(){
var $wall = $('#posts');
$wall.imagesLoaded(function(){
$wall.masonry({
itemSelector: '.entry, .entry_photo',
isAnimated : false
});
});

$wall.infinitescroll({
navSelector : '#pagination',
nextSelector : '#pagination a',
itemSelector : '.entry, .entry_photo',
bufferPx : 2000,
debug : false,
errorCallback: function() {
$('#infscr-loading').fadeOut('normal');
}},
function( newElements ) {
var $newElems = $( newElements );
$newElems.hide();
$newElems.imagesLoaded(function(){
$wall.masonry( 'appended', $newElems,{isAnimated: false}, function()   {$newElems.fadeIn('fast');} );
});
}); $('#posts').show(0);
});    

1 个答案:

答案 0 :(得分:0)

function( newElements ) {
    var $newElems = $(newElements);
    // Get IDs for new Elements 
    var $newElemsIDs = $newElems.map(function (){return this.id;}).get();
    $newElems.hide();
    // Tell Tumblr we need new LikeButton statuses
    Tumblr.LikeButton.get_status_by_post_ids($newElemsIDs);
    $newElems.imagesLoaded(function(){
        $wall.masonry( 'appended', $newElems,{isAnimated: false}, function() {
            $newElems.fadeIn('fast');
        });
    });
    $('#posts').show(0);
});