I am writing a simple fade-slideshow with previous
and next
buttons.
The problem is that when I click the next
button very quickly (for example 2 times), before the first event finished, the second one will be executed, so for less than a second I will see, two images in my page.
$("#next_button").click(function (){
$("#slide"+current_slide).fadeOut(FADE_DURATION, function () {
current_slide ++;
current_slide = current_slide % slides_number;
$("#slide"+current_slide).fadeIn(FADE_DURATION, function (){
$(".slide_image").not("#slide"+current_slide).attr("style", "display: none;");
});
});
});
In the last line, after
fadeIn()
, I even tried to hide everything except current image, wishing the issue will be solved, but that doesn't work.I read something about
event.stopImmediatePropagation()
but I couldn't use it, or maybe it wasn't my solution.
How to force jQuery
to ignore executing any similar events, before one of those same events, get finished?