I have a flex div, in which there are 3 more divs with different amounts of content, which when you click on the button translateX(-100%) are shifted translateX(-100%) . In order to keep the footer under the content of the current slide, I need to hide the content of the previous one, but only after it leaves viewport, for this I use setTimeout (), when reaching the last slide, all the content returns to translateX(0) , but for some reason, hidden content is not displayed.
let count = 0; let services = Array.from(document.querySelectorAll('article')); $('#services-prev').on('click',function(){ if(count>0) { count--; $('.services-slide').css('transform',`translateX(-${count*100}%)`); $('#services-articles article').css('transform',`translateX(-${count*100}%)`); $('.services-item',services[count]).show(); }; }); $('#services-next').on('click',function(){ if(count<3) { count++; $('.services-slide').css('transform',`translateX(-${count*100}%)`); $('#services-articles article').css('transform',`translateX(-${count*100}%)`); setTimeout(function(){$('.services-item',services[count-1]).hide()},500); } if(count>=3){ $('.services-item').show(); count = 0; //$('.services-slide').appendTo($('.services-slider-container')); $('.services-slide').css('transform',`translateX(0)`); $('#services-articles article').css('transform',`translateX(0)`); } });