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 p开发者_运维技巧eriod and runs straight away.
jQuery(document).ready(function($) {
setTimeout($.mainmenuslider({
trigger:'close'
}),6000);
});
Any Ideas???
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).
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);
});
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);
精彩评论