I'm using the Isotope plugin for the grid of a Wordpress page. I would like to use Isotope's imagesLoaded
option in order to avoid the images on the page overlapping when the page is loaded. Can someone explain to me where and how in my existing code I have to use imagesLoaded
?
jQuery(function ($) {
var $container = $('#isotope-list');
$container.isotope({
itemSelector : '.item',
layoutMode : 'masonry',
percentPosition: true
});
//Add the class selected to the item that is clicked, and remove from the others
var $optionSets = $('#filters'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('#filters');
$optionSets.find('.selected').removeClass('selected');
$this.addClass('selected');
//When an item is clicked, sort the items.
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
});
UPDATE:
I tried adding imagesLoaded but it causes the Isotope plugin to stop working entirely. Here's the code with imagesLoaded added:
jQuery(function ($) {
var $container = $('#isotope-list').imagesLoaded( function() {
$container.isotope({
itemSelector : '.item',
layoutMode : 'masonry',
percentPosition: true
});
});
//Add the class selected to the item that is clicked, and remove from the others
var $optionSets = $('#filters'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('#filters');
$optionSets.find('.selected').removeClass('selected');
$this.addClass('selected');
//When an item is clicked, sort the items.
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
});
I am linking to the imagesLoaded script in the header of the page but I am getting the following error when inspecting the page in Chrome: