News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

Changing two images on mouse over using JavaScript

Started by ben2ong2, October 04, 2006, 04:07:16 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

ben2ong2

To change two images simultaneously, we extend the roll() function we made in the previous article, so that it takes four arguments instead of two. The first two specify the name and source for image1 while the other two for image2.

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--

function roll(img_name1, img_src1, img_name2, img_src2)
   {
   document[img_name1].src = img_src1;
   document[img_name2].src = img_src2;
   }

//-->
</SCRIPT>

The JavaScript function above can be placed in the HTML head or in an external JavaScript file (.js) so that it loads right at the beginning of the document.
This function expects four arguments. The function is called from onmouseover and onmouseout event handlers and the four parameters are passed to it.


<A HREF="somewhere.html"
onmouseover="roll('sub1', 'movedown.gif', 'sub2', 'an1.gif')"
onmouseout="roll('sub1', 'moveup.gif', 'sub2', 'an2.gif')">

<IMG SRC="moveup.gif" NAME="sub1" WIDTH="143"
HEIGHT="39" BORDER="0">
</A>

<IMG SRC="an2.gif" NAME="sub2" WIDTH="143" ALIGN="39">

Finally we'll get to know how to preload images so that the rollovers are smooth.



You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login