Image Mouse on and out : Mouse Event « Event « JavaScript DHTML






Image Mouse on and out

  
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
<!--
if (document.images)
{
 // Preload original Images
 var pic1_init= new Image();
 pic1_init.src="http://www.java2s.com/style/logo.png";
 var pic2_init= new Image();
 pic2_init.src="http://www.java2s.com/style/logo.png";
 var pic3_init= new Image();
 pic3_init.src="http://www.java2s.com/style/logo.png";
 var pic4_init= new Image();
 pic4_init.src="http://www.java2s.com/style/logo.png";

 // Preload images for mouseover
 var pic1_new= new Image();
 pic1_new.src="http://www.java2s.com/style/logoRed.png"; 
 var pic2_new= new Image();
 pic2_new.src="http://www.java2s.com/style/logoRed.png";
 var pic3_new= new Image();
 pic3_new.src="http://www.java2s.com/style/logoRed.png";
 var pic4_new= new Image();
 pic4_new.src="http://www.java2s.com/style/logoRed.png";
}

function change_it(the_name)
{
 if (document.images)
 {
  document.images[the_name].src= eval(the_name+"_new.src");
 }
}

function change_back(the_name)
{
 if (document.images)
 {
  document.images[the_name].src= eval(the_name+"_init.src");
 }
}
//-->
</SCRIPT>

</HEAD>

<BODY>

<A HREF="#" onMouseOver="change_it('pic1')" onMouseOut="change_back('pic1')"><IMG SRC="http://www.java2s.com/style/logo.png" name="pic1" id="pic1" border="0"></A>
<P>
<A HREF="#" onMouseOver="change_it('pic2')" onMouseOut="change_back('pic2')"><IMG SRC="http://www.java2s.com/style/logo.png" name="pic2" id="pic2" border="0"></A>
<P>
<A HREF="#" onMouseOver="change_it('pic3')" onMouseOut="change_back('pic3')"><IMG SRC="http://www.java2s.com/style/logo.png" name="pic3" id="pic3" border="0"></A>
<P>
<A HREF="#" onMouseOver="change_it('pic4')" onMouseOut="change_back('pic4')"><IMG SRC="http://www.java2s.com/style/logo.png" name="pic4" id="pic4" border="0"></A>

</BODY>

</HTML>
           
         
    
  








Related examples in the same category

1.Catches and manages the mouse's events
2.Mouse and key event (IE)
3.Mouse in image and out
4.Mouse cross hairs
5.Mouse Drag and Drop
6. Creating a Rollover Effect
7.Codependent Link Tag and the onMouseOver Event
8.Which mouse button was clicked?
9.Which element was clicked
10.Mouse over event
11.Get component From Point (Mouse)
12.Cutting and Pasting under Script Control
13.Using Drag-Related Event Handlers
14. Using onDragEnter and onDragLeave Event Handlers
15.Using onMouseDown and onMouseUp Event Handlers
16.Dragging Elements with onMouseMove
17.Using the toElement and fromElement Properties
18. The onBeforeCopy Event Handler
19.Called from an onmousedown event handler
20.Mousedown event handler of an object within a Layer
21.Cursor Arrival and Departure
22.Use Mouse over action to transfer url location
23.Get mouse position with on mouse move event (IE)
24.Get mouse position in mouse down event (IE)
25.H1 double click events
26.Return boolean value for on click event
27.Register mouse down event(IE)