Jump to content

Set Timeout Doesn't Work


MrFish

Recommended Posts

I'm very confused because my setTimeout only works without quotes.setTimeout(changeRotary, 5000); works (but is not the results I want)but setTimeout("changeRotary()",5000); does not.And it doesn't matter what I have in the function because I've only got an alert in there. Anyone ever had this problem?

Link to comment
Share on other sites

That line looks syntactically correct (in fact, your first bit of code is not supported by all browsers).What does your entire script look like?

Link to comment
Share on other sites

After doing some reading I have found that my timeouts aren't in scope. But I don't know how to fix it. My full script is long but I'll post it. But as you can see I'm making a rotary. I want it to cycle through every 8 seconds.Screenshot:betarotary.pngSome of the code may seem unnecessary because I have, for example, 3 functions for the same hover. But I'm pretty sure it's necessary. But there is so much mashed together here I don't know how you will be able to make anything out of it. The only reason I have any clue what's going on is because I wrote it :)

	/* Rotary */	rotaryItems = 0;	rotaryNumber = 0;	checkNumber = 0;			function rotaryFade()	{		$("#rotaryImage").fadeOut();	}			function changeRotary()	{		rotaryNumber ++;		checkNumber ++;		$("#rotaryButtons div").each(function(){			if($(this).hasClass("selected"))			{				$(this).removeClass("selected").fadeTo("slow", 0.6);			}		});		number = $("#rotaryImage").attr("number");		if(number == rotaryItems)		{			number = 0;		}		number ++;		$("#rotaryButtons div").each(function(){			if($(this).attr("number") == number)			{				var imageLocation = $(this).attr("imageLocation");				$(this).addClass("selected").fadeTo("slow", 1);				$("#rotaryImage").attr("src", imageLocation).attr("number", number);				$("#rotaryImage").fadeIn();				setRotaryTimeouts()			}		});			}		function setRotaryTimeouts()	{		setTimeout("rotaryFade()",7500);		setTimeout("changeRotary()",8000);	}		function quickNextRotary(){		rotaryFade();		setTimeout("changeRotary()", 500);	}		$("#rotary").ready(function(){				setRotaryTimeouts()					$("#rbl2").fadeOut("fast");		$("#rbr2").fadeOut("fast");				$("#rotaryButtons :first").addClass("selected").fadeTo("slow", 1);				$("#rotaryButtons div").each(function(){			var firstButtonSource = $(this).attr("buttonLocation");			$(this).append("<img src='" + firstButtonSource + "'>");			rotaryItems += 1;		});				var firstImageSource = $("#rotaryButtons :first").attr("imageLocation");		$("#rotaryImage").attr("src", firstImageSource);	});		$("#rotaryButtonsLeft").hover(function(){		$("#rbl2").fadeIn("slow");	}, function(){		$("#rbl2").fadeOut("slow");	});		$("#rotaryButtonsRight").hover(function(){		$("#rbr2").fadeIn("slow");	}, function(){		$("#rbr2").fadeOut("slow");	});		$("#rotaryButtonsRight").hover(function(){		$("#rotaryButtons .rotaryButton").each(function(){			var position = $(this).position();			$(this).css("left", position.left+1);		});	});		$("#rotaryButtons div").click(function(){		$("#rotaryButtons .selected").fadeTo("fast", 0.6).removeClass("selected");		$(this).fadeTo("fast", 1).addClass("selected");		var buttonNumber = $(this).attr("number");		var imageSource = $(this).attr("ImageLocation");		$("#rotaryImage").attr("src", imageSource).attr("number", buttonNumber);	});		$("#rotaryButtons div").hover(function(){		$(this).fadeTo("fast", 1);	}, function(){		if(!$(this).hasClass("selected"))		{			$(this).fadeTo("fast", 0.6);		}	});

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...