Search code examples
jqueryhtmldelay

using delay before an animation begins instead of queue a delay


I would like to start an animation after 5 seconds (so not right when the page loads but a few more seconds after that)

i try using delay but it doesnt seem to work, where am i wrong? is there a way to create a timer for it to count down before it starts?

$(document).ready(function(){
    $(".info").delay(5000).css({marginLeft:'-999px'}).animate(
        {marginLeft: '0px'},{duration: 2000, queue:false});
    $(".jamey").css({left:'999px'}).animate(
        {left:'606px'},{duration:2000, queue: false});
    $(".jamey2").css({left:'999px'}).animate(
        {left:'606px'},{duration:2000, queue: false});
    $(".rip-date").css({left:'999px'}).animate(
        {left:'375px'}, {duration:2000, queue: false});
    $('#overlay').animate({ opacity: 1, }, 5000, function(){
            // done fading.
    });
    $(".info").css({color:'#191919'});

Solution

  • delay is generally better for adding a delay between animations. In this case, I would use a setTimeout:

    $(document).ready(function() {
        setTimeout(function() {
            //Your code here...
        }, 5000); 
    });