User:Meagan/DotOrg/files/mouseover.js

From 2008.igem.org

< User:Meagan | DotOrg | files
Revision as of 18:59, 22 July 2008 by Meagan (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

function init()
{
	if (document.getElementById)
		var x = document.getElementById('mouseovers').getElementsByTagName('IMG');
	else if (document.all)
		var x = document.all['mouseovers'].all.tags('IMG');
	else return;
	var preloads = new Object();
	for (var i=0;i<x.length;i++)
	{
		preloads['n'+x[i].id] = new Image;
		preloads['n'+x[i].id].src = 'pix/'+ x[i].id + '_nrm.jpg';
		preloads['o'+x[i].id] = new Image;
		preloads['o'+x[i].id].src = 'pix/'+ x[i].id + '_omo.jpg';
		preloads['o'+x[i].id].onerror = function () {this.src='pix/default.gif'}
		x[i].onmouseover = function () {this.src=preloads['o'+this.id].src;}
		x[i].onmouseout = function () {this.src=preloads['n'+this.id].src;}
	}
}