Jump to content

Animation With Arguments


Shinji

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...