SetTimeout not working with jquery

I have an advanced jquery function that works fine, but when I pass it through setTimout, it does not wait for the specified period and starts immediately.

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

Any ideas ???

+5
source share
3 answers

You need to pass an anonymous method to do what you want, for example:

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

Otherwise, you are trying to pass the result of the function (to execute it immediately, and do not run it later).

+15
source

You call the function right there when you try to set a timeout to happen later. Instead of this:

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

!

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

setTimeout() , .

:

setTimeout("call_this_function()", 4000);
+2

All Articles