0

Hi all,
I'm trying my first bit of jQuery code but am familiar with Java programming. I'm trying to create a function that loads a div with an image in it, which will fade in and then after 4 seconds move onto the next image. I want it to create an infinite loop but it doesn't work.

<script type="text/javascript">
		$(document).ready(function ()
	{
		var slide=true;
		while (slide==true)
		{
			var i=1;
			for(i=1;i<3;i++)
			{
				$(#main[i]).fadeIn('200');
				setTimeout(4000);
				$(#main[i].hide();
				if (i==2)
				{
					i=1;	
				}	
			}
		}
	});
	</script>

How do I fix this?

Cheers,

Edited by bsewell: n/a

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by rajarajan07
0

You WANT it to create an infinite loop? And what is the purpose of the outer loop? What is setTimeout _supposed_ to be doing (you're missing a function parameter to setTimeout)?

0

I want to create a image slideshow by placing an image in each div. I want it to continue to animate while the user is on the page. So each div will be displayed for 4 seconds, and then another div will fade in and display for 4 seconds.

0

You don't need a while loop to make a loop, just use setInterval(<repeat every N milliseconds>, <function to execute>);

0

Loop never solve your issue, because in faction of seconds your loop got ended or become infinite. So please search for some timer function which set intervals like the above reply says. I suggested as a bad programming. Sure in JQuery timer functions would be there? Jquery handled many transition effects. So this is not the way you do. Get into that or google it for an example.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.