home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

beginner javascript, trying to put objects in array stupidity

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1506
Discussions: 200,952, Posts: 2,379,474, Members: 246,315
Old March 23rd, 2009, 11:34 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Mar 2009
Posts: 1
beginner javascript, trying to put objects in array stupidity

I'm playing with the Yahoo UI animation stuff, trying to animate divs. I have it working OK but I'm a noob at javascript so struggling with the idea of looping over to populate and array with objects. The code block thats commented out (tag2) works fine if its hardcoded but I'm trying to generate 10-20 keyword divs that can be animated to the input field (well they will fly towards it, fade to white before arrival and then I will populate the input with the text in the div...or so i had planned )

Any help appreciated.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
 
<title>Animating Motion</title> 
 
<style type="text/css"> 
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style> 
 
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/fonts/fonts-min.css" /> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/animation/animation-min.js"></script> 
 
 
<!--begin custom header content for this example--> 
<style type="text/css"> 
.tag {
	display: block;
	float: left;
	padding:1px;
	margin:0 0 0 3px;
	text-decoration: none;
	text-align:center;
	background-color:#cccccc;
	border:silver 0px solid;
	cursor:pointer;
}

.tag a:link , .tag a:visited{
	text-decoration: none;
}

#spacer {
    background:#ccc;
    margin-bottom:1em;
    height:200px;
    width:100px;
}
</style> 
 
<!--end custom header content for this example--> 
 
</head> 
 
<body class=" yui-skin-sam"> 


<div align="center">
<form>
<input type="text" id="input" name="tags" value="" size="30" tabindex="1">
</form>
</div>

<div id="spacer"></div>

<div class="tag" id="tag1"><a href="#">guidelines</a></div>
<div class="tag" id="tag2"><a href="#">policy</a></div>
<div class="tag" id="tag3"><a href="#">finance</a></div>
<div class="tag" id="tag4"><a href="#">PCT</a></div>
<div class="tag" id="tag5"><a href="#">immunisation</a></div>

<script type="text/javascript">

(function() {
var x = YAHOO.util.Dom.getX('input')+2;
var y = YAHOO.util.Dom.getY('input')+2;

    var totalTagDivs = YAHOO.util.Dom.getElementsByClassName('tag', 'div').length; 
 
   var attributes = {
        points: { to: [x,y] }
    };
	
	var colorAttributes = { 
        color: { to: '#06e' }, 
        backgroundColor: { to: '#fff' } 
    }; 
// tag1

var move=new Array();
var changeColor=new Array();

for(i=1; i<totalTagDivs+1; i++)
{

     move[i] = new YAHOO.util.Motion('tag'+i, attributes);
     changeColor[i] = new YAHOO.util.ColorAnim('tag'+i, colorAttributes); 
	move[i].onStart.subscribe(function() {
		changeColor[i].animate();
	});
    YAHOO.util.Event.on('tag'+1, 'click', function() {
        move[i].animate();
    });

}


// tag2
//    var move2 = new YAHOO.util.Motion('tag2', attributes);
//    var changeColor2 = new YAHOO.util.ColorAnim('tag2', colorAttributes); 
//	move2.onStart.subscribe(function() {
//		changeColor2.animate();
//	});
//    YAHOO.util.Event.on('tag2', 'click', function() {
//        move2.animate();
//    });

	
})();
</script>

</BODY> 
</HTML>
Saulg is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner in Javascript, need help with Firefox add-on gschmidt Webmastering and Programming 2 October 29th, 2008 07:54 PM
Beginner in Javascript I need help!! overdosed20 Webmastering and Programming 6 June 24th, 2008 12:34 PM
Beginner Javascript question James Engle Webmastering and Programming 0 April 21st, 2008 11:43 PM
Beginner, javascript code help! snikker74 Webmastering and Programming 4 April 4th, 2008 12:08 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
The disrespect of Obama by Russian .. (41)
Is It Just Me? (2942)
Making Health Care Worse (178)
Wireless Televisions. (12)
CPU fan stops spinning randomly (8)
windows 7 problem (7)
Regular Build (11)
Is the PSU I received dead? (12)
radeon x850xt platinum & shader.. (6)
Print spooler problem (15)
windows vista security holes (10)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Foreign voltage (10)
Recent Discussions
How to Enjoy Your Favorite Videos on .. (0)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Modern Warfare 2: Who Bought It? (63)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Laptop with wireless problem. (3)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
windows vista security holes (10)
Point and Shoot Camera Suggestions. (4)
Multiple Restarts Required at Boot (2)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)
How to convert MP3's (4)
Wireless Televisions. (12)
Hp Artist Edition + Matching Bag (0)
Asus P4G8X Mobo (6)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)
windows 7 internet problem (5)
BSOD On Startup (ntoskrnl.exe) (2)


All times are GMT -4. The time now is 02:27 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28