views:

73

answers:

3

I have a jquery extended function that works perfectly but when i pass it through the setTimout it does not wait the the specified period and runs straight away.

jQuery(document).ready(function($) {    
  setTimeout($.mainmenuslider({
    trigger:'close'
  }),6000);  
});

Any Ideas???

+7  A: 

You're calling the function right there when you're trying to set up the timeout to happen later. Instead:

jQuery(function($) {
  setTimeout(function() {
    $.mainmenuslider({trigger:'close'});
  }, 6000);
});
Pointy
+9  A: 

You need to pass an anonymous method to do what you want, like this:

jQuery(function($) {    
    setTimeout(function() {
      $.mainmenuslider({
        trigger:'close'
      });
    }, 6000);    
});

Otherwise you're trying to pass the result of the function (making it execute immediately, and run nothing later).

Nick Craver
A: 

Try This!!

jQuery(document).ready(function($) {    
  setTimeout("$.mainmenuslider({
    trigger:'close'
  })",6000);  
});

while using the setTimeout() , always try specifying the action need to be called in quotes.

Ex:

setTimeout("call_this_function()", 4000);
Ashin
That is not actually a good idea. Look at the other answers for examples of the proper way to do this.
Pointy
4 spaces before a line format it as code. Select a block and hit `ctr-k` to do this.
Peter Ajtai