最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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') });

发布评论

评论列表(0)

  1. 暂无评论