|
|
Changing two images on mouse over using JavaScriptTo 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.
<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 contents: Changing two images simultaneously on mouseover using javascript.
Page URL: http://www.webdevelopersnotes.com/tips/html/ changing_two_images_on_mouse_over_using_javascript.php3
|
|