3

Possible Duplicate:
jQuery delay between animations

I have created two functions: One that animates an object from Point A to Point B, and the second, that animates from Point B to C. I would like to have a time delay betweeen the 2 functions. Can someone please tell me how to achieve this. My unsuccessful attempt was:

movt_1().delay(5000).movt_2();

Also, I would like to have a delay right at the beginning BEFORE the first animation runs

Thanks!

1
  • If you do a search for jQuery delay between animations, you'll get literally dozens of questions similar to or identical to this one. Commented May 24, 2011 at 3:16

3 Answers 3

3

the jQuery .delay() function only works for functions that use the queue. For example, according to the docs, the parameterless .show() and .hide() will not work. If you are using a function you wrote, you can use the setTimeout() javascript function instead.

Sign up to request clarification or add additional context in comments.

Comments

2
function movt_1 ()
{
  //your code here
  setTimeout (movt_2, 5000);
}

function movt_2 ()
{
  //your code here
}

setTimeout (movt_1, 5000);

EDIT: Changed the first parameter to the "proper" way.

7 Comments

That should be setTimeout(movt_1, 5000); and setTimeout(movt_2, 5000);
Not sure, but w3cschool says different: w3schools.com/js/js_timing.asp
+1 to @qertymk, I've used it before and you don't have to put the double quotes and the parentheses.
Great, so both statements are equivalent.
@Hyperboreus: That site isn't the authoritative place for javascript. Check out w3fools.com to see what I mean
|
1

jQuery's .delay() function only works with items in the animation queue.

The example below uses .delay() and a callback function to modify the 2nd element:

$('#test1').hide('fade', {}, 1000).delay(3000).hide(0, function() {
    $('#test2').show(0).delay(3000).hide();
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.