0

Here's the fiddle:

http://jsfiddle.net/4mmk2/

Rapidly clicking the button will cause the animation to pause halfway. I suspect it's the stop() function's problem but I can't find a way to fix it. By the way, I use stop to prevent jQuery from putting all the sliding animations in the queue.

chenglou
  • 3,640
  • 2
  • 25
  • 33

2 Answers2

1

Try:

$('a').toggle(function() {
    $('div').stop(1,1).slideUp()
}, function() {
    $('div').stop(1,1).slideDown()
})​

jsFiddle example

Set the clearQueue and jumpToEnd properties of the stop method to true.

j08691
  • 204,283
  • 31
  • 260
  • 272
1

toggle() is deprecated you can try slideToggle():

$('a').click(function(e) {
    e.preventDefault();
    $('div').stop(true,true).slideToggle()
})

http://jsfiddle.net/4mmk2/3/

Ram
  • 143,282
  • 16
  • 168
  • 197
  • Since when is toggle() deprecated? – j08691 Aug 03 '12 at 20:16
  • 1
    @j08691 as of jQuery 1.7, toggle() as an event has been deprecated. http://api.jquery.com/category/deprecated/ – Ram Aug 03 '12 at 20:22
  • Thanks for the answer and the info. Just curious though, I've noticed that my problem persists if I set the second parameter of stop() to false. Is there a way to still solve the problem without making the animation jump to the finish? – chenglou Aug 03 '12 at 20:30
  • Yes, it works on jsfiddle but not in my page. I'll try to fix it. Thanks. – chenglou Aug 03 '12 at 21:21