Unobtrusive Image Rollover with Prototype Library.
prototype.js and rollover.js to your javascript directory.<script type="text/javascript" src="javascripts/prototype.js"></script> <script type="text/javascript" src="javascripts/rollover.js"></script>
id to its parent container.
<ul id="nav">
<li><a href="#"><img src="images/home_sel.gif" width="69" height="13" alt="Home" /></a></li>
<li><a href="#"><img src="images/about_us.gif" width="90" height="13" alt="About Us" /></a></li>
<li><a href="#"><img src="images/products.gif" width="153" height="13" alt="Products & Services" /></a></li>
<li><a href="#"><img src="images/news.gif" width="69" height="13" alt="News" /></a></li>
<li><a href="#"><img src="images/contact_us.gif" width="101" height="13" alt="News" /></a></li>
</ul>
<script type="text/javascript">
window.onload = function() {
new Rollover('nav');
}
</script>
Or call it from the body tag onload event:
<body onload="new Rollover('nav');">
By default, Rollover javascript assumes rollover image name has _over suffix, and the selected image has _sel suffix. Example:
about_us.gif
// Rollover image
about_us_over.gif
// Selected image
about_us_sel.gif
If you don't like the naming convention, you can change them by passing the following options when initializing the Rollover object.
<script type="text/javascript">
window.onload = function() {
new Rollover('nav', {suffixSeperator: '-', rolloverSuffix: 'hover',
selectedSuffix: 'active'});
}
</script>