Changing two images on mouse over - javascript image mouse rollover - javascript image rollover - image rollover using javascript
changing two images on mouse over, javascript image mouse rollover, javascript image rollover, image rollover using javascript
Changing two images on mouse over using JavaScriptGo to Changing two images on mouse over using JavaScriptHTML & JavaScriptGo to HTML and JavaScript tips and tricksTips and tricksGo to web development Tips and tricksHomepage

Changing two images on mouse over using JavaScript

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.

Image change on mouseoverChange image on mouseover
<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" HEIGHT="39">

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

| Page 1 | Page 2 | Page 3 | Page 4 |

AddThis Social Bookmark Button


Page contents: Changing two images on mouse over - javascript image mouse rollover - javascript image rollover - image rollover using javascript

Page URL: http://www.webdevelopersnotes.com/tips/html/ 44.php3



Join Mailing List


Feedback/Questions




50+ web hosting FAQs

Search engine for your website

Free software from Google - The Google Pack Collection

Create your own search engine
Search WebDevelopersNotes.com