-
March 23rd, 2009, 10:34 AM #1Junior 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>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Beginner in Javascript, need help with Firefox add-on
By gschmidt in forum Webmastering and ProgrammingReplies: 2Last Post: October 29th, 2008, 06:54 PM -
Beginner in Javascript I need help!!
By overdosed20 in forum Webmastering and ProgrammingReplies: 6Last Post: June 24th, 2008, 11:34 AM -
Beginner Javascript question
By James Engle in forum Webmastering and ProgrammingReplies: 0Last Post: April 21st, 2008, 10:43 PM -
Beginner, javascript code help!
By snikker74 in forum Webmastering and ProgrammingReplies: 4Last Post: April 4th, 2008, 11:08 AM



LinkBack URL
About LinkBacks



Reply With Quote

AMD has dropped to fourth in the microprocessor sales rankings due to demand for mobile device processors, with Qualcomm and Samsung substantially boosting their sales of ARM chips.
AMD Fourth in Microprocessor Sales