Shinji Posted May 11, 2007 Share Posted May 11, 2007 Hello, and thanks for looking! I am getting better at javascript and want to use it to animate multiple images. I looked at your animation tutorial and saw that really it would be dumb to create the functions over and over again (cuz that would kinda defeat the purpose of a function), so I attempted to create my own with arguments, although I do not have a good grasp on this. Please review what I came up with: <script type="text/javascript">function mouseOver(name,src_over){document.(name).src = "(scr_over)"}function mouseOut(name,src_out){document.(name).src = "(src_out)"}</script> This is my JS, and I really am pretty sure I didn't do the arguments right, but I figured the two that would be needed are the name of the image element as well as the new src.Later on I have something like this: <a href="index.php"><img src="images/home.gif" width="75" height="30" border="0" alt="Home" name="img1" onmouseOver="mouseOver('img1','images/home-over.gif')" onmouseOut="mouseOut('img1','images/home.gif')" /></a> If I am way off can someone please post new code or critique mine?Thanks! Link to comment Share on other sites More sharing options...
jesh Posted May 11, 2007 Share Posted May 11, 2007 I think you're on the right track. One suggestion I would like to offer is for you to start moving away from using the "name" attribute in your HTML and start using "id" instead. If you do that, you can get at your elements much easier using document.getElementById.HTML <img id="img1" /> Javascript var myImage = document.getElementById("img1"); So, your functions, as they are written, would look more like this: function mouseOver(id,src_over){ document.getElementById(id).src = src_over;} Link to comment Share on other sites More sharing options...
Shinji Posted May 12, 2007 Author Share Posted May 12, 2007 Cool! I thank you for the response as well as the awesome tip. I will try again with this and see if i can get a hold of it.-edit-Thanks again! I was able to do it with the script you gave me! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.