I create a button that when it is clicked, moves some images but when I click quickly the button, jQuery create an error on the movement of the images. So I want disable the button untill that the .animate() function isn’t finish. I tryed write this code but isn’t correct.
var next = $('.next');
function nextAction(e){
e.preventDefault();
next.off('click');
if(pellicle.css('left').replace(/[^-\d\.]/g, '') <= -(stepTotalWidth - screenWidth)){
pellicle.animate({
left:'0'
},1000, function(){next.on('click', nextAction);});
}
else {
pellicle.animate({
left:'-=' + screenWidth
},1000);
}
}
next.on('click', nextAction);
You can attach and detach events as many as you want, i didn’t get what is the question exept that you have o problem with click in period when you ‘off’ event while animation running.
For this you can attach another event that will prevent default and second will run animanion
The second thing is that
pellicle.css('left')is always returns ***px in that case a bit faster than regexp would beparseInt(pellicle.css('left'), 10) || 0it will always give you a number in that case.