I have an Isotope gallery (version 2) with almost 400 elements. A typical gallery item looks like this:
<div class="element hybrid a" data-category="hybrid">
<p class="type">H</p>
<h2 class="name">Name</h2>
<p class="strain-info">No Info Available</p>
<p class="review"><a class="button radius small black review-form-lb" href="#review-form-lightbox">Review</a></p>
</div>
For instance when I run the code below, which basically adds a class to the element clicked, it takes several seconds for the element to enlarge.
$container.on( 'click', '.element', function() {
$( this ).toggleClass('large');
$container.isotope('layout');
});
Another example is if I have a button group that contains several options to filter the gallery, again it takes several seconds. Filter JS:
$('#filters').on( 'click', '.button', function() {
var $this = $(this);
// get group key
var $buttonGroup = $this.parents('.button-group');
var filterGroup = $buttonGroup.attr('data-filter-group');
// set filter for group
filters[ filterGroup ] = $this.attr('data-filter');
// combine filters
var filterValue = '';
for ( var prop in filters ) {
filterValue += filters[ prop ];
}
// set filter for Isotope
$container.isotope({ filter: filterValue });
});
Here is the variable for $container
// init Isotope
var $container = $('.isotope').isotope({
itemSelector: '.element',
layoutMode: 'fitRows',
filter: function() {
return qsRegex ? $(this).text().match( qsRegex ) : true;
}
});
I should note that the above code works great when there is a small number of items. How could I improve the performance of the gallery?
I should note that in version 1 of Isotopes I have the same gallery and it works fine. I am upgrading because of enhanced abilities of v2 of isotopes.
Here is the live site - IMPORTANT! - This site is for a marijuana dispensary in Colorado, USA. Website may not be appropriate for work.
Update
I tried changing all div
s to li
elements. Didn't see much improvement.
I tried turning on hardware acceleration per mfirdaus's answer but it didn't appear to work.
Note: The above link to the live site is a stripped down version where I removed everything not required for the Isotope gallery. It is slightly faster than when I originally posted this, however, it needs to be more responsive. Try using it on a tablet and it takes several seconds for the Isotope item to respond.
Update 2
Version One of Isotopes performs much better with a large gallery and I ended up using version one because of this.
div
over anli
element would matter much but I have been surprised before. => I will give it a try. – Paragraphiali
elements didn't work but it saved a few bytes of data at the least. => – ParagraphiaanimationOptions removed. jQuery animation removed. This means no animation for IE8 and IE9.
– Paragraphia