Is there a way to replace this timeout with a getter/ setter. I need the images in the filter gallery to sort accordingly by waiting to find out what the globalVariable is when a user clicks on a section.
Right now, I use a timeout, which doesn't work after one click. Here is one question I looked at, but I'm still having a hard time wrapping my head around it. Here is the codepen. What would be the best approach to achieve this?
Part of the Code: /* Generate all items on "All" then on click generate the ones that match the globalVariable */
$grid.revealItems(GenerateItems(8));
/*This click function doesn't repeat, which means no more items load after second click*/
var variableSet = document.getElementById("filterList");
variableSet.addEventListener('click', runFunction);
function runFunction(){setTimeout (function(){
$grid.revealItems(GenerateItems(4));
}, 1000)}
/* Filter on Click */
$(document).on("click", ".filter-item", function clickFilter() {
$(".filter-item.active").removeClass("active");
$(this).addClass("active");
var f = $(this).data("f");
//Global Variable
globalVariable = $(this).attr('name');