I have a content slider, additionally I made “prev” & “next” buttons. The buttons should only be clickable when the animation is complete (animations duration is 500ms). I tried to solve it with the :animated selector, but it won’t work:
if (!$(".scrollContainer").is(':animated')) {
$(".nextItems a").click(function() {
$(".slideNavig").find('a.selected').removeClass('selected').parent().next().find("a").addClass('selected');
});
}
if (!$(".scrollContainer").is(':animated')) {
$(".prevItems a").click(function() {
$(".slideNavig").find('a.selected').removeClass('selected').parent().prev().find("a").addClass('selected');
});
}
Or quite simply, I need to stop the buttons click event for 500ms after a click. Can anyone help me please?
Move the if statement that checks if the thing is animated inside your click event handler:
Also you could dry out your code by doing something like this: