开发者

create a delay between the running of functions [duplicate]

This question already has an answer here: Closed 11 years ago.

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 attem开发者_开发问答pt 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!


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.


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.


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();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜