jQuery .fadeIn() effect, can set to a timer?

The effect described here:

http://api.jquery.com/fadeIn

Its easy enough to make things happen when you click on target elements, but what if I wanted to make elements fade in and out based on a timer and not based on user action? For example, to build a simple slide show, where every 4 seconds I fade one element (image) out and another in? Is this possible?

Thank you!
Brad BansnerWeb DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
>>Its easy enough to make things happen when you click on target elements
Bingo! If you can do that, then you just need to "click" whatever element needs clicking, but instead of doing it "manually" you click it programmatically - ex:

$("#item1").trigger("click");
0
Brad BansnerWeb DeveloperAuthor Commented:
OK, so .trigger is used to simulate the clicking of an element, which could "trigger" the fade in and fade out. But how do I make the trigger happen every x number of seconds?
0
hieloCommented:
>>..But how do I make the trigger happen every x number of seconds?
Like I said, "...If you can do that, "


So I guess you need everything.  Refer to the accepted solution I posted here:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_24693777.html
0
Terry_focusCommented:
Hi,

There are two methods for setting timer in javascript

A countdown timer setTimeout, which performs the action once or setInterval which repeatedly does the action. See below for example of setInterval (sounds more like what you want)

http://www.w3schools.com/js/js_timing.asp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<title>Untitled Document</title>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
		<style>
			div {
				width:100px;
				height:100px;
				display:block;
				background:#ff0000;
			}
		</style>
		<script type="text/javascript">
		
		$(function(){
			//Every 1 second change the fade
			setInterval(function(){
				//Do your jQuery action
				if($("#foo:visible").length>0){
					$("#foo").fadeOut(500);
				}else{
					$("#foo").fadeIn(500);
				}
				
			},1000);
		})		
		</script>
	</head>
	<body>
		<div id="foo">
    	</div>
	</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brad BansnerWeb DeveloperAuthor Commented:
Yes, I think that will help a lot, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.