Created
March 2, 2011 16:23
-
-
Save jbennett/851195 to your computer and use it in GitHub Desktop.
simple image swap/preload script for Joomla/Mootools 1.11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (window, document, undefined) { | |
window.addEvent('load', function() { // dont need to fill domready | |
$$('img').each(function(img) { | |
var normal, rollover; | |
if (img.src.indexOf('_normal') === -1) | |
return; // do nothing if image doesn't have _normal in name | |
normal = img.src; | |
rollover = img.src.replace('_normal', '_rollover'); // get both filenames | |
new Asset.image(rollover, { | |
onload: function() { | |
img.addEvents({ | |
mouseenter: function() { | |
img.src = rollover; | |
}, | |
mouseleave: function() { | |
img.src = normal; | |
} | |
}); | |
} | |
}); | |
}); | |
}); | |
})(this, this.document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment