Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell jQuery to ignore clicks during an animation sequence

Tags:

jquery

delay

I'm in the midst of writing a slide show app (click a button, and you slide through a list of images) for jQuery, but I've run into a little bug where it will respond to the click() request even while an animation is happening. I'm using the animate() function already, so that isn't staving off the additional animation requests.

Any way to program around this?

like image 223
dclowd9901 Avatar asked Mar 22 '10 01:03

dclowd9901


1 Answers

You can check whether the animation is in progress in the click handler:

if ($(this).is(':animated')) return false;

Alternatively, you can use the live or delegate functions to only bind the handler to non-animated elements:

$('something:not(:animated)').live('click', function() { ... });
like image 68
SLaks Avatar answered Oct 02 '22 12:10

SLaks