javascript - JQuery UI: Bounce animation queuing but stop() not working - Stack Overflow

I am using the bounce animation from JQuery UI:$('.mydiv').mouseover(function () {$(this).eff

I am using the bounce animation from JQuery UI:

$('.mydiv').mouseover(function () {
      $(this).effect("bounce", { times:4 }, 300);
});

And I have the old problem of the animation 'queuing' if I hover over them (ie: if I move the mouse over a div rapidly 4 times the animation will occur one after the over 4 times).

Normally I would use .stop() to deal with it, eg:

$('.mydiv').mouseover(function () {
      $(this).stop().effect("bounce", { times:4 }, 300);
});

But in this instance it doesnt make any difference. Does anyone know of a solution?

Using .stop(true) means the animations stop witout pleting the bounce like so:

I am using the bounce animation from JQuery UI:

$('.mydiv').mouseover(function () {
      $(this).effect("bounce", { times:4 }, 300);
});

And I have the old problem of the animation 'queuing' if I hover over them (ie: if I move the mouse over a div rapidly 4 times the animation will occur one after the over 4 times).

Normally I would use .stop() to deal with it, eg:

$('.mydiv').mouseover(function () {
      $(this).stop().effect("bounce", { times:4 }, 300);
});

But in this instance it doesnt make any difference. Does anyone know of a solution?

Using .stop(true) means the animations stop witout pleting the bounce like so:

Share Improve this question edited Aug 7, 2012 at 0:44 MeltingDog asked Aug 7, 2012 at 0:27 MeltingDogMeltingDog 15.6k52 gold badges178 silver badges322 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

Use the :animated selector with the .is() method to test if the element already has an animation in progress. If so, don't start the bounce:

$('.mydiv').mouseover(function () {
    var $this = $(this);
    if (!$this.is(":animated"))
      $this.effect("bounce", { times:4 }, 300);
});

.stop() accepts two paramters, both of which default to false.

There's param1, or clearQueue --which will clear all other animations behind it from the queue and stop the animation in it's track.

Then there's param2, or jumpToEnd - which will finish the animation immediately.

if you set .stop(true) It should work as intended.

Yes, it's impossible to stop (finish) and dequeue jQueryUI (but not core jQuery) animation with .stop() if it is only... not used twice. :)

It's just a "trick" to change the order of what it performs. So, try this:

$('button').on('click', function(){ $(this).stop(false, true).stop(true, false).animate('bounce') });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745607258a4635741.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信