944,008 Members | Top Members by Rank

Ad:
0

Image Swap with the Mouse

by on Feb 5th, 2005
Swap two images as you move your mouse in and out of the image field. Uses onMouseOver, onMouseOut and a short javascript code.
JavaScript / DHTML / AJAX Code Snippet (Toggle Plain Text)
  1. <!-- Experiments with images vegaseat 6/15/04 -->
  2. <!-- onMouseOver, onMouseOut, JS -->
  3.  
  4. <html>
  5. <head>
  6.  
  7. <title>Swap Images with onMouseOver and onMouseOut</title>
  8.  
  9. </head>
  10. <body bgcolor="#FFFFCC" text="#3300FF">
  11.  
  12.  
  13. <CENTER>
  14. <FORM NAME = form1>
  15. <H2>
  16. Move the mouse across to swap the image ...
  17. </H2>
  18. <A HREF="" name= link1 onMouseOver = "ImgOver()" onMouseOut = "ImgOut()">
  19. <IMG NAME = "IMG1" SRC = "c:/windows/web/wallpaper/follow.jpg" WIDTH = 800 HEIGHT = 600>
  20. </A>
  21. </CENTER>
  22.  
  23. <SCRIPT LANGUAGE= JavaScript>
  24.  
  25. function ImgOver()
  26. {
  27. // use an image file you have or use one of XP's wallpaper
  28. document.form1.IMG1.src = 'c:/windows/web/wallpaper/home.jpg';
  29. }
  30.  
  31. function ImgOut()
  32. {
  33. // use an image file you have or use one of XP's wallpaper
  34. document.form1.IMG1.src = 'c:/windows/web/wallpaper/follow.jpg';
  35. }
  36.  
  37. </SCRIPT>
  38.  
  39. </body>
  40. </html>
Comments on this Code Snippet
Apr 12th, 2006
0

Re: Image Swap with the Mouse

Is no closing <form> tag required here? What could you use to give a name to instead of a form to refer to in the document.whatever.IMG1.src line? I've tried using several things I give names to but they don't work. Hmm..

Take a break and go to:

Check out: http://www.wsiwebsitestudio.com/thebeat.html
Newbie Poster
egaus is offline Offline
1 posts
since Mar 2006
Jul 2nd, 2008
0

Re: Image Swap with the Mouse

ok
Newbie Poster
wiko is offline Offline
1 posts
since Jul 2008
Jan 14th, 2009
0

Re: Image Swap with the Mouse

the code is unneccessarily complex
<img src='image1.jpg' onmouseover='src="image2.jpg";' onmouseout='src="image1.jpg";'>
the only javascript required is to load the second image in the background after the page is loaded and displayed, so there is no mouseover delay

[icode] ...snip ..

</body>
<script language="javascript" type="text/javascript">
//<![CDATA[
<!--
image2 = new Image();
image2.src = "image2.jpg";
//-->
//]]>
</script>
</html>[/icode}
Posting Maven
almostbob is online now Online
2,970 posts
since Jan 2009
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: please help about Dojo grid
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Word press and javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC