Created
July 21, 2016 02:51
-
-
Save dominicgan/b982b887f2f8343c4a8ca53d64dfd4f1 to your computer and use it in GitHub Desktop.
Isotope with filtering in vanilla js
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
var grid = document.querySelector('#portfolio .portfolio-list'); | |
console.log(grid); | |
var iso = new Isotope(grid, { | |
itemSelector: '.portfolio-list__item', | |
filter: '.cat-commercial, .cat-healthcare, .cat-retail, .cat-hospitality', | |
// sortAscending: { | |
// name: true, | |
// date: false | |
// }, | |
masonry: { | |
percentPosition: true, | |
columnWidth: '.portfolio-list__sizer', | |
gutter: '.portfolio-list__gutter' | |
}, | |
stagger: 10, | |
transitionDuration: '0.6s' | |
}); | |
// bind filter button on click | |
var gridFilters = document.querySelectorAll('#portfolio .portfolio-filter .portfolio-filter__item button'); | |
for(i = 0; i < gridFilters.length;i++) { | |
gridFilters[i].addEventListener('click', function(){ | |
console.log(' '+this.parentElement.getAttribute('class')+' '+this.dataset.filter); | |
var filterValue = this.dataset.filter; | |
// use filter if matches value | |
iso.arrange({ filter: filterValue }); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment