Sunday, 8 September 2013

jQuery: do not add more clicks

jQuery: do not add more clicks

I hope to explain myself properly.
We have something like this (a simple example):
$('#click').click(function() {
$('#a').animate({width: 'toggle'}, 1500);
$('#b').animate({width: 'toggle'}, 1500);
$('#b').animate({width: 'toggle'}, 1500);
});
Now, if I click several times on "#click", even before the effects are
finished, my repeated clicks are added together and the function executed
multiple times (it's a really unpleasant thing especially when using
"hover", as you know).
But I would like that clicks are detected only if effects are finished.
How can I do?
I read the documentation about queue, but I'm not sure that will work in
this case.
Can I have some examples?
Thank you.

No comments:

Post a Comment