简体   繁体   English

当与tumblr中的Infinite Scroll一起使用时,砌体插件返回错误

[英]Masonry plugin returning error when used with Infinite Scroll in tumblr

I know alot has been written about this, but I feel I am close to solving the issue. 我知道已经写了很多有关此的文章,但是我觉得我已经接近解决问题了。

I am trying to use a theme which has masonry installed, but now the client is asking for infinite scroll and this is causing me issues. 我正在尝试使用已安装砖石的主题,但是现在客户端要求无限滚动,这导致了我的问题。

Initially I was seeing errors in the console for both the masonry and infinite scroll plugins, now at least I am only seeing a masonry error. 最初,我在控制台中看到砖石和无限滚动插件的错误,现在至少我仅看到砖石错误。 And it does look as though the infinite scroll function is calling subsequent pages of posts, it's just that Masonry is struggling to append them to the page in the right layout. 而且看起来无限滚动功能正在调用帖子的后续页面,只是Masonry努力将它们以正确的布局添加到页面中。

I think it is something to do with my callback function, but worried I may also need to call an imagesLoaded function (this plugin is also called via the theme). 我认为这与我的回调函数有关,但担心我可能还需要调用imagesLoaded函数(此插件也通过主题调用)。

I have a copy of the current theme here: http://kod-temp.tumblr.com/ 我在这里有当前主题的副本: http : //kod-temp.tumblr.com/

The inline script looks like this: 内联脚本如下所示:

var $wall = $('#posts');

$(window).load(function () {
// Grid
    $wall.masonry({
    columnWidth: 84, 
    itemSelector: '.post:visible'
});

// infinite scroll
$('#posts').infinitescroll({
    navSelector  : ".pagination", // selector for the paged navigation (it will be hidden)
    nextSelector : ".pagination a:first", // selector for the NEXT link (to page 2)
    itemSelector : "#posts .post" // selector for all items you'll retrieve
},
// trigger Masonry as a callback
function( newElements ) {
    var $newElems = $( newElements );
    $wall.masonry( 'appended', $newElems );
    }
);

The markup follows a simple block like this: 标记遵循一个简单的块,如下所示:

<div id="posts">
    <article class="post"></div>
</div>

The error is: 错误是:

 Uncaught TypeError: undefined is not a function 
 masonry.js:10

( http://static.tumblr.com/qlf79cn/tGeleg9g0/masonry.js ) http://static.tumblr.com/qlf79cn/tGeleg9g0/masonry.js

Well I finally have some working code on this. 好吧,我终于有了一些有效的代码。 The js now looks like this: js现在看起来像这样:

(function () {
    var $tumblelog = $('#posts');
    $tumblelog.infinitescroll({
        navSelector: ".pagination",
        nextSelector: ".pagination a:last-child",
        itemSelector: "article",
    }, function (newElements) {
        var $newElems = $(newElements).css({
            opacity: 0
        });
        $newElems.imagesLoaded(function(){
            $newElems.animate({
                opacity: 1
            });
            $tumblelog.masonry('appended', $newElems);
        });
    });
    $tumblelog.imagesLoaded(function(){
        $tumblelog.masonry({
            columnWidth: 84
        });
    });
})();

The imagesLoaded script was required (as this question has also been raised by me here ). 需要使用imagesLoaded脚本(因为我在这里也提出了这个问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM