2

My HTML:

<div>
    <p>Testing Paragraph</p>
    <span>Testing Span</span>
    <div class="content">This is the main content of this div</div>
</div>

My jQuery:

$('p').click(function () {
    $(this).parent().find('.content').slideToggle('slow');
});

Fiddle: http://jsfiddle.net/Vs5DX/

As you can see from the demo, the content will slide up and slide down when you click the paragraph. The problem is that if I click the paragraph for many times very fast then it's continuously going up and down without clicking.

I've tried:

$(this).parent().find('.content').stop(true).slideToggle('slow'); 

But it's even worse when the animation stop going. Any ideas?

2 Answers2

1

You can use :not to exclude the current :animated elements:

$('p').click(function () {
    $(this).parent().find('.content:not(:animated)').slideToggle('slow');
}); 

Updated Fiddle

Eli
  • 14,779
  • 5
  • 59
  • 77
0

Start with a variable:

varClicked = false;

on slideDown make it as true, allow slideUp only if it is true, on SlideUp, make it false again

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
Mihai Alin
  • 89
  • 1
  • 2
  • 9