Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTimeout not working with jquery

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???

like image 939
Wright-Geek Avatar asked Jul 16 '10 12:07

Wright-Geek


1 Answers

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).

like image 182
Nick Craver Avatar answered Sep 18 '22 19:09

Nick Craver