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.
You're on the right track with
queue
, just check the length of the queue, e.g.:Live Example | Live Source
You can create a tiny plug-in for this, if you like:
...and then use it like this:
Live Example | Live Source
Re your comment below:
For combining the results of animations with other asynchronous things, you'd probably want to use
Deferred
andPromise
objects. You can get thePromise
for an animation from the jQuery set using.promise
; e.g.:You can then combine that promise with other promises/deferreds via
$.when
andPromise#then
.