By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,714 Members | 1,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,714 IT Pros & Developers. It's quick & easy.

mouseover JS question

P: 1
OK, I am new to Javascript but good with CSS and HTML coding. I have a little experience with Java and .NET as well. Here's what I'm trying to do.

I have three images of an animated spider. The first image is a simple gif with transparency (spider.gif - which is the state of the rollover when the page loads) and two other gif files. One is an animation of the spider turning counterclockwise (spider_f.gif) a bit, and the other is a reverse animation that returns it to the starting position(spider_r.gif).

I'm trying to get the code to activate on a mouseover and use a) spider.gif_f.gif if the image is in the start position or the spider_r.gif position. If moused over again it would then activate the spider_r.gif, and so forth.

The animation works fine on the first mouseover, but not on subsequent mouseover events. Here is what I have currently:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3.  
  4. <HTML>
  5.  
  6. <HEAD>
  7.  
  8. <TITLE>Test Title</TITLE>
  9.  
  10. <script language="javascript">
  11. <!--
  12.  
  13. function roll2(img_name2)
  14.    {
  15.     if (document[img_name2].src = "images/spider/spider_f.gif")
  16.     {document[img_name2].src = "images/spider/spider_r.gif";}
  17.  
  18.     else
  19.     {document[img_name2].src = "images/spider/spider_f.gif";}
  20.    }
  21.  
  22. //-->
  23. </script>
  24.  
  25.  
  26. </HEAD>
  27.  
  28. <BODY>
  29.  
  30. <IMG SRC="images/spider/spider.gif" width="90" height="104" border="0" 
  31. ALT="Jumping Spider" name="spider2" onmouseover="roll2('spider2')">
  32.  
  33.  
  34. </BODY>
  35.  
  36. </HTML> 
Any help would be greatly appreciated!
Thanks!!
Nov 17 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
On line 15, for comparison, you need to use == (double equals) as opposed to single equal.
Nov 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.