[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • Last Modified:

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!
0
bbdesign
Asked:
bbdesign
  • 2
  • 2
1 Solution
 
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
 
bbdesignAuthor 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
 
bbdesignAuthor Commented:
Yes, I think that will help a lot, thanks!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now