0

Suppose I have this animation that start at some point :

myElement.animate({ top: -currentTempImageX, left: -currentTempImageY }, 5000);

that take 5 seconds to animate! Suppose I want to stop it after 2 seconds. Can I have this control?

Thank you

markzzz
  • 47,390
  • 120
  • 299
  • 507

3 Answers3

4

Yes, you can

myElement.stop();

Link: http://api.jquery.com/stop/

If you want to stop the animation after 2 seconds then use,

setTimeout(function(){myElement.stop();}, 2000);
Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70
0

User setTimeout() as suggested by Bhuvan Rikka , for stop that use clearTimeout() function .. for example see this link

http://www.w3schools.com/js/js_timing.asp

Jageen
  • 6,345
  • 2
  • 37
  • 56
0

You may also check the FX queue (used for the jquery animations)

http://api.jquery.com/queue/

or this other topic.

What are queues in jQuery?

Community
  • 1
  • 1
Pedro Ivo
  • 11
  • 2