Jump to content

Attempt to fade in 8 images one at a time

Recommended Posts

I am attempting to fade in 8 images, one at a time with a delay between each one.


I have used the following code.

/* I have 8 <div>s, named "one", "two", "tre" ... etc.. */		var divs = ["one", "two", "tre", "for", "fiv", "six", "svn", "egt"];/* initially these divs all have an attribute of display:none    I step through each elemet in the "divs" array,    I take the litteral "div#, and append to it the value of the current array element,   and pass this value to the slowShow function. */		for (var i=0;i<divs.length;i++) {			setTimeout(slowShow("div#"+divs[i]), 555555);		};		/* the function slowShow calls a jQuery function using the value passed to that function    as the selector for the jQuery function */		function slowShow(param) {			$(param).fadeIn( 2400 );		};/* the snipit of code displays the 8 individual divs all at once,    though they all use the fadeIn value of 2400 */

The entire page code is attached, but the images are not.

Please note, Initially a class was used to give all divs the attribute of display:none. All divs had that class, plus a unique identifier. I was hoping that by using the ID as the jQuery selector, I might be able to display each div individually, one by one. But they all display at once, as though I was using the class in my selector. I already tried placing a display:none attribute in each unique div identifier. That didn't help, so I changed it back to using a class to set all the divs to display:none.



Link to post
Share on other sites

Your loop is executing the slowShow function immediately, not scheduling it to run later. You are scheduling the return value of slowShow to run later, but it doesn't return a function. You can use an anonymous function to wrap the call to slowShow inside, and then all of them will fade in 9 and a quarter minutes later, still at the same time though. If you want to stagger when they fade in then change the number of milliseconds each time to call setTimeout.

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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