Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Tumblr类按钮不工作_Javascript_Jquery_Tumblr - Fatal编程技术网

Javascript Tumblr类按钮不工作

Javascript Tumblr类按钮不工作,javascript,jquery,tumblr,Javascript,Jquery,Tumblr,我正在设计一个tumblr主题,它使用砖石结构和无限滚动代码,如果您需要查看它。like按钮在所有帖子上都会正确显示,在前几篇帖子上有效,但在新加载的帖子上不起作用 每个帖子都添加了{PostID}id。我对Javascript的理解非常差,因此我认为这就是问题所在: $(function(){ var $container = $('#content'); $container.imagesLoaded(function(){ $container.masonr

我正在设计一个tumblr主题,它使用砖石结构和无限滚动代码,如果您需要查看它。like按钮在所有帖子上都会正确显示,在前几篇帖子上有效,但在新加载的帖子上不起作用

每个帖子都添加了{PostID}id。我对Javascript的理解非常差,因此我认为这就是问题所在:

$(function(){
    var $container = $('#content');
    $container.imagesLoaded(function(){
        $container.masonry({
            itemSelector: '.entry',
            isAnimated:true,
            columnWidth:1,
            animationOptions:{duration:350, queue:false},
            isFitWidth: true,
        });
    });

    $container.infinitescroll({
            navSelector  : '#page-nav',    // selector for the paged navigation 
            nextSelector : '#page-nav a',  // selector for the NEXT link (to page 2)
            itemSelector : '.entry',     // selector for all items you'll retrieve
            loading: {
                finishedMsg: '{lang:No more posts}',
                img: 'http://24.media.tumblr.com/tumblr_m3j5g3KlEm1r0fipko8_r1_100.gif'
            }
        },
        // trigger Masonry as a callback
        function( newElements ){
            // hide new items while they are loading
            var $newElems = $( newElements ).css({ opacity: 0 });
            // ensure that images load before adding to masonry layout
            $newElems.imagesLoaded(function(){
                // show elems now they're ready
                $newElems.animate({ opacity: 1 });
                isAnimated:true
                $container.masonry( 'appended', $newElems, true ); 
            });
            // videos
            $newElems.find('.video').each(function(){
                resizeVideos();
                console.log($newElems, $newElemsIDs);
                Tumblr.LikeButton.get_status_by_post_ids($newElemsIDs);
            },
            function(){
                $container.masonry();
            });
        }
    );
});

任何帮助都将不胜感激

尽管这个问题是重复的,但它是一个不完整的副本/噩梦

加载的图像

$newElems.imagesLoaded(function(){
    // show elems now they're ready
    $newElems.animate({ opacity: 1 });
    isAnimated:true
    $container.masonry( 'appended', $newElems, true ); 
});
  • isAnimated:true
    将出错,因为它是用于调用
    的键/值
  • 喜欢按钮

    $newElems.find('.video').each(function(){
        resizeVideos();
        console.log($newElems, $newElemsIDs);
        Tumblr.LikeButton.get_status_by_post_ids($newElemsIDs);
    },
    
  • $newElemsIDs
    从未定义或填充
  • Tumblr.LikeButton.get_status_by_post_id($newElemsIDs)将出错
  • Tumblr.LikeButton.get_status\u by_post_ids()
    只有在
    infiniteScroll
    结果包含视频帖子时才会被调用
  • })丢失
  • 砌体

    function(){
        $container.masonry();
    });
    
  • $container.mashise('added',$newElems,true)已经告诉
    砌体
    有新项目,无需再次调用
  • 全套意大利面

    $(function(){
        var $container = $('#content');
        $container.imagesLoaded(function() {
            $container.masonry({
                itemSelector: '.entry',
                isAnimated:true,
                columnWidth:1,
                animationOptions:{duration:350, queue:false},
                isFitWidth: true,
            });
        });
    
        $container.infinitescroll({
                navSelector  : '#page-nav',    // selector for the paged navigation 
                nextSelector : '#page-nav a',  // selector for the NEXT link (to page 2)
                itemSelector : '.entry',     // selector for all items you'll retrieve
                loading: {
                    finishedMsg: '{lang:No more posts}',
                    img: 'http://24.media.tumblr.com/tumblr_m3j5g3KlEm1r0fipko8_r1_100.gif'
                }
            },
    
            // trigger Masonry as a callback
            function( newElements ) {
    
                // hide new elements
                var $newElems = $( newElements ).css({ opacity: 0 });
    
                // create $newElemsIDs
                var $newElemsIDs = $newElems.map(function () { 
                    return this.id; 
                }).get();
    
                // give tumblr the $newElemsIDs
                Tumblr.LikeButton.get_status_by_post_ids( $newElemsIDs );
    
                // ensure that images load before adding to masonry layout
                $newElems.imagesLoaded( function() {
    
                    // tell masonry we have added new elems
                    $container.masonry( 'appended', $newElems, true ); 
    
                    // show $newElems
                    $newElems.animate({ opacity: 1 });
                });
    
                // resize videos for $newElems
                $newElems.find('.video').each( function() {
                    resizeVideos();
                });
            }
        );
    });
    

    这一行末尾有一个额外的逗号:
    isFitWidth:true,
    应该是这样:
    isFitWidth:true
    @EhsanT谢谢!我已经修复了这个错误,但是like按钮仍然不起作用。请查看以下答案:我不同意的可能重复,它是重复的,我的投票仍然存在。非常感谢!是的,我的观点是,我无法理解代码中哪些部分是必需的,当脚本超过3行时,我会有点不知所措。。。感谢您对每个部分的解释,非常感谢!:)