javascript - Stop fadin/fadeout event jquery -
i have dive flashs once on click. if press button multiple times keep flashing until click count has been executed. if user click button multiple times, stop flashing after last click.
example https://jsfiddle.net/va6njdry/
$('button').click(function () { $('div').fadeout().fadein().fadeout().fadein(); });
use stop stop previous animations.
$('button').click(function () { $('div').stop(true, true).fadeout().fadein().fadeout().fadein(); // ^^^^^^^^^^^^^^^^ }); demo: https://jsfiddle.net/tusharj/va6njdry/1/
docs: http://api.jquery.com/stop/
stop currently-running animation on matched elements.
edit
thanks @awolff
you can use finish
$('button').click(function () { $('div').finish().fadeout().fadein().fadeout().fadein(); // ^^^^^^^^ }); demo: https://jsfiddle.net/tusharj/va6njdry/4/
docs: https://api.jquery.com/finish/
stop currently-running animation, remove queued animations, , complete animations matched elements.
Comments
Post a Comment