tags:

views:

25

answers:

2

I'm using the jQuery Cycle plugin to cycle through some words, but I don't want it to start or show any of the words until a few seconds after page load, perhaps 10 seconds or so.

This is the code I have:

$(document).ready(function() {

 $('#questions').cycle({ 
    delay:  10000, 
    speed:  2000
});
});

What would be the best way to wait 10 seconds and then run the cycle function and also show the content that will be hidden by default. Thanks.

+1  A: 

Just use the javascript setTimeout function.

setTimeout(function(){
    $('#question').cycle({ speed: 2000 });
    // Other code to show whatever you want goes here, ie. $('some selector').show();
}, 10000);
laurencek
One problem with this is that all the divs inside questions will be shown as the cycle code hasn't run yet. The idea is to hide all the divs inside on page load and then after 10 seconds show the cycles first child div but fade it in the same as the cycle would any other div so effectively just delaying the start but hiding em all before they start.
Cameron
Could you not just use CSS to hide them to start with? Or set some JavaScript at the bottom of the page, not in .ready or anything, that hides the divs?
laurencek
A: 

You can use the setTimeOut() function:

$(function(){
  setTimeOut(function(){
    $('#questions').cycle({ 
        delay:  10000, 
        speed:  2000
    });
  }, 5000)
});
Sarfraz