我在将Wordpress中的无限滚动插件与使用砌体的主题集成在一起时遇到了一个棘手的问题。

我拥有最新版本的无限滚动2.6.2,并且我在插件的回调部分中添加了以下代码:

// hide new items while they are loading
var $newElems = jQuery(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 );
});

但是它不起作用,它给新元素增加了不透明度,但是没有增加位置等,所以效果不佳。新产品位于旧产品页面上方。

脚本看起来像:
/* <![CDATA[ /
var infinite_scroll = "{\"loading\":{\"msgText\":\"Loading...<\\/em>\",\"finishedMsg\":\"No additional products.<\\/em>\",\"img\":\"http:\\/\\/www.test.com\\\/wp-content\\\/plugins\\\/infinite-scroll\\\/img\\\/ajax-loader.gif\"},\"nextSelector\":\".next\",\"navSelector\":\".woo-pagination\",\"itemSelector\":\"li.product\",\"contentSelector\":\"ul.products\",\"debug\":false,\"behavior\":\"\",\"callback\":\"\\\/\\\/ hide new items while they are loading\r\nvar $newElems = jQuery(newElements).css({ opacity: 0 });\r\n\\/\\/ ensure that images load before adding to masonry layout\r\n$newElems.imagesLoaded(function(){\r\n\\/\\/ show elems now they're ready\r\n$newElems.animate({ opacity: 1 });\r\n$container.masonry( 'appended', $newElems, true );\r\n});\"}";
/ ]]> */

砌体看起来像:
// Only fire masonry if the window is an appropriate size and images are loaded
jQuery(function(){
    var $container = jQuery('ul.products');
    $container.imagesLoaded( function(){
        if (jQuery(window).width() > 767) {
            $container.masonry({
                itemSelector : 'li.product',
                columnWidth : 295,
                isFitWidth: true,
                gutterWidth : 2
            });
        }
    });
});

最佳答案

WordPress无限滚动插件Here's the link,有一个名为behavior的选项,您可以在其中选择 Masonry ,当然,您需要选择正确的选择器,然后它会像一个符咒一样起作用,以查看更多开发选项访问the developers website

关于javascript - woocommerce中带有砌体的无限滚动不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19679268/

10-09 08:24