dweb Posted October 11, 2012 Share Posted October 11, 2012 Hi I have the following jQuery code $(document).ready(function() { function slider(panel) { jQuery("#"+panel).animate({ top: '-=30' }, 400); } setTimeout(slider('panel1'), 400); setTimeout(slider('panel2'), 800); setTimeout(slider('panel3'), 1200); } But it seems to run straight away and the inital delay doesn't seem to happen, and it also only seems to only animate "panel1" and ignores "panel2" and "panel3" Any idea why this might be happening? Thanks Quote Link to comment Share on other sites More sharing options...
kicken Posted October 11, 2012 Share Posted October 11, 2012 But it seems to run straight away and the inital delay doesn't seem to happen The way you wrote your setTimeout calls, you are telling JS to "execute the slider function NOW, then register what it returns to be executed LATER". To run the slider function later, you need to wrap it in another function. You can just use an anonymous function for that: setTimeout(function(){ slider('panel1'); }, 400); setTimeout(function(){ slider('panel2'); }, 800); setTimeout(function(){ slider('panel3'); }, 1200); Quote Link to comment Share on other sites More sharing options...
dweb Posted October 11, 2012 Author Share Posted October 11, 2012 Wicked, that seemed to cure all the problems, thanks man Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.