0

I have a script that I would like to delay from running for 2 seconds maybe 3 then execute, at the moment I use document.ready is there a way to add a time value so its still document.ready but add 3 seconds.

$(document).ready(function() {
   function bikepass2(){
     bike.css('left', startPos);
     bike.animate({left: -450}, 8000, 'linear')
   };

    var screenWidth = $(document).width();
    var startPos = screenWidth;
    var bike = $('#bike2')
    bikepass2();
    setInterval(function() {
      bikepass2();
    }, 15000);
  });
0

3 Answers 3

2

Add the function inside a setTimeout. http://www.w3schools.com/jsref/met_win_settimeout.asp. In the time add 3000 for 3 seconds.

setTimeout( function() 
{
    //add the function that you want to execute after 3 seconds

}, 3000);
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

setTimeout( function() 
{
    //do something special
}, 3000);

Put in inside document.ready()

Hope it helps.

Comments

1

Javascript has no sleep() function, which causes the script to pause.

But you can use .setTimeout() to run a method delayed:

window.setTimeout(myFunc(), 1000);

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.