Infinite scroll with masonry in woocommerce not working
Asked Answered
I

1

6

I'm facing a nasty problem with integrating the infinite scroll plugin in Wordpress with the theme that is using masonry.

I have the latest version of infinite scroll, 2.6.2, and I have added this code in the callback section of the plugin:

// 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 );
});

but it's not working, it adds the opacity to the new elements but it's not adding the positions,etc, so not quite working; the new items are going on the top of the page over the old products.

Script looks like:

/* <![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});\"}";
/ ]]> */

the masonry looks like:

// 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
            });
        }
    });
});
Isoagglutination answered 30/10, 2013 at 10:6 Comment(0)
E
3

The plugin of infinite scroll for wordpress: Here's the link , has an option named behavior where you can choose the Masonry, and of course you need to choose the selectors right and after that will work like a charm, to see more dev options you can access the developers website

Eaddy answered 29/11, 2013 at 10:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.