Created
September 19, 2023 19:09
-
-
Save luckyscooby/9886ef8bb26478def3d45028ab7705e9 to your computer and use it in GitHub Desktop.
Isotope.js Example for Webflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Michael Leocádio @ 2016--> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.min.js"></script> | |
<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.1.8/imagesloaded.pkgd.min.js></script> | |
<script> | |
// add dynamic class | |
jQuery | |
( '.w-dyn-item .categoria' ).each | |
( | |
function( index, element ) | |
{ | |
var _this = jQuery( element ); | |
_this.parent().parent().addClass( _this.text().toLowerCase() ); | |
} | |
); | |
$(document).ready( function() { | |
// init Isotope | |
var $grid = $('.grid').isotope({ | |
itemSelector: '.w-dyn-item', | |
sortBy : 'random' | |
}); | |
// layout Isotope after each image loads | |
$grid.imagesLoaded().progress( function() { | |
$grid.isotope('layout') | |
}); | |
// store filter for each group | |
var filters = {}; | |
$('.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 = concatValues( filters ); | |
// set filter for Isotope | |
$grid.isotope({ filter: filterValue }); | |
}); | |
// change is-checked class on buttons | |
$('.button-group').each( function( i, buttonGroup ) { | |
var $buttonGroup = $( buttonGroup ); | |
$buttonGroup.on( 'click', 'button', function() { | |
$buttonGroup.find('.is-checked').removeClass('is-checked'); | |
$( this ).addClass('is-checked'); | |
}); | |
}); | |
}); | |
// flatten object by concatting values | |
function concatValues( obj ) { | |
var value = ''; | |
for ( var prop in obj ) { | |
value += obj[ prop ]; | |
} | |
return value; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment