Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/269348-simple-jquery-animations/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.