I have a css grid. When you click a div, it will toggle a class that makes it expand, then after 3000ms, the class is toggled again and the div collpases back to original size. The user should be able to over-ride this delay, so that if they want to collapse the div before the 3s setTimeout has elapsed, they can do it.
My issue is that when this happens, it doesn't cancel the set timeout function, and then the user input and the old 'lagging' code begin to overlap, which creates a mess and breaks my logic.
heres the code:
var open = false;
function dissolveExpand(parent, sibling, tte){
if(open==false){
open=true;
toggle(parent, sibling, tte);
} else{
open=false;
toggle(parent, sibling, tte);
};
};
function closer(parent, sibling, tte){
if(open==true){
toggle(parent, sibling, tte);
};
console.log(open);
};
function toggle(parent, sibling, tte){
parent.classList.toggle("expanded-div");
sibling.classList.toggle("hidden-div");
tte.classList.toggle("expanded-tap");
};
tte_parent1.onclick = function(){
dissolveExpand(tte_parent1, sibling1, tte1);
setTimeout(function(){closer(tte_parent1, sibling1, tte1); }, 3000);
};`
If I sit here and spam click the tte_parent element, the code just stops working properly.
Sorry for the lack of specifics but I'm stuck