I'm using queue to do a non stop animation (a blink animation), but when I try to stop it, I'd like that the animation runs until the stack end and not stop immediatly.
- <html>
- <head>
- <script src="http://code.jquery.com/jquery-latest.min.js"></script>
- <style>
- div {
- position: absolute;
- top: 0px;
- left: 0px;
- width: 200px;
- height: 200px;
- border: 2px black solid;
- background-color: green;
- }
- </style>
- </head>
- <body>
- <input type="button" value="Stop it!" />
-
- <div id="foo"><p>Hello</p></div>
-
- <script type="text/javascript">
- var blink = function(next) {
- $("div").animate({left: '+=500px'}, 2000);
- $("div").animate({left: '-=500px'}, 2000, blink);
-
- if($.isFunction(next)) {
- next();
- }
- };
- $("div").queue('blink', blink);
- $("div").dequeue("blink");
-
- $("input").click(function() {
- $("div").stop();
- });
- </script>
- </body>
- </html>
My question is : how to stop the animation when the div is on his initial position ?