简体   繁体   English

以特定速度滚动时的砌体和无限滚动打破布局

[英]Masonry and Infinite Scroll breaking layout when scrolling at certain speed

I have a fluid width theme and I am using jQuery Masonry and Infinite Scroll. 我有一个宽度可变的主题,正在使用jQuery Masonry和Infinite Scroll。 The Problem is that if you scroll at a certain speed (not too fast and not too slow) the page it can cause a break in the grid. 问题是,如果您以一定的速度滚动(不太快也不太慢),页面可能会导致网格中断。 I have only seen this with two columns and in Firefox: 我只在两栏和Firefox中看到了这一点:

屏幕布局

Anyone know why this is happening? 有人知道为什么会这样吗? I know it could be a number of things but if anyone has had experience with this and knows what is going on it would help greatly. 我知道这可能是很多事情,但是如果有人对此有经验并知道发生了什么,那将有很大帮助。

UPDATE: The break happens right after the last post on the page. 更新:中断发生在页面上的最后一个帖子之后。 The ones that come after are being generated by infinite scroll's callback. 无限滚动的回调会生成之后的内容。

Well, I can not see the link to your page to look at (and the image is not available) but from my past experiences with masonry, whenever there is a major change in the page size (re-sizing, scrolling, re-sized divs) you need to trigger it again: 好吧,我看不到要查看的页面链接(并且该图像不可用),但是根据我过去的砌体经验,只要页面大小发生重大变化(调整大小,滚动,调整大小) divs),则需要再次触发它:

jQuery(document).ready(function() {
    jQuery("#somediv").click(function() {
        jQuery('#leftcol').toggle(700); //div resizing start here
        jQuery('#somediv2').toggleClass("minside");
        jQuery('#somediv').toggleClass("full"); // evoke again after change..
        jQuery('#container').masonry({
            itemSelector : '.item',
            columnWidth : 240
        });
    });
});

Add this as callback for infinite scrolls and your problem will be gone... at least works for me: 将此添加为无限滚动的回调,您的问题将消失……至少对我有用:

// 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 });
        $container.masonry('appended', $newElems, true);
    });

});

Check the $container just in case you've changed it. 以防万一您更改了$container

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

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