最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin3PV0评论

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

Post a comment

comment list (0)

  1. No comments so far