I have a problem with an animation.
var i = 0;
$('.next').on('click', function() {
if (i < 4) {
$('li').animate({'left': '-=600px'}, 300);
i++;
}
console.log($('li:first').position().left);
console.log(i);
});
$('.back').on('click', function() {
if ($('li:first').position().left < 0) {
$('li').animate({'left': '+=600px'}, 300);
i--;
}
console.log(i);
});
https://jsfiddle.net/6t1wx95f/10/
When you click 4 times on the button 'Next', you will see all the images and everything works fine. But if you click on it many times and very fast, it will stop working and you won't see the last image.
So there are 2 options for me:
- The animation should go on (in this case very fast), no matter how fast the button has been clicked.
- Wait 300ms until the animation is finished and then go on with
i++
ori--;
.
What's the easiest way to fix it?