0

I made a simple gallery where when you click on a image thumb nail, it will show the larger image with fade in fade out effect with jquery.

$('#thumnail').click(function(){
  $('#piccontainer').fadeOut(function(){
      $('#piccontainer').html('<div> <img src="' + imgsource + '"  /> </div>');
  });

  $('#piccontainer').fadeIn();
});

but if i click on a 5 different thumbnails quickly, the large image will fade in fade out for all 5 images. How can I disable so that lets say i clicked on 5 thumbnails very quickly, it should only fadein the last 5th one. basicaly how can i stop the queue of the click events?

thanks for the help.

3
  • Look at the API, but I'd suggest: stop(true,true). Commented Mar 8, 2012 at 19:14
  • .bind will ensure that quick clicks dont get registered until an action is finished api.jquery.com/bind Commented Mar 8, 2012 at 19:15
  • i tried the bind, same result. where would i add stop? in this case Commented Mar 8, 2012 at 19:20

3 Answers 3

1

Take a look at - http://api.jquery.com/queue/

Sign up to request clarification or add additional context in comments.

Comments

0

You could use timeout like this to avoid multiple clicks. Again this is possible to avoid clicks for a small amount of time and not longer.

http://jsfiddle.net/dhavaln/Z7w84/

1 Comment

i'm sure this is a common issue and must be dealt many times.
0

Add this condition at the top of the function:

if ($('#piccontainer').is(":animated")) {
  return false;
}

See Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.