You need to create a recursion so that the function calls itself. A crutch was created:
function startSlider(items, delay) { $(items[0]).fadeIn(300) .delay(delay) .fadeOut(300) .promise() .done(function() { items.splice(0, 1); if (items.length > 0) { startSlider(items, delay); } else { //sliderRetry($(".offer-scrin"), delay); startSlider(items, delay); } }); } function sliderRetry(items, delay) { return startSlider(items, delay); } This all works, but on pages where this function is not needed, a "many recursion" error is caused.
How to do it right?
return false;. For example, the first line of thestartSliderfunctionstartSliderto doif (!$(items[0]).length) return false;- cyadvertsliderRetryis not mentioned anywhere in the code. ButstartSliderlaunches itself so. - cyadvert