Skip to content

Instantly share code, notes, and snippets.

@jbennett
Created March 2, 2011 16:23
Show Gist options
  • Save jbennett/851195 to your computer and use it in GitHub Desktop.
Save jbennett/851195 to your computer and use it in GitHub Desktop.
simple image swap/preload script for Joomla/Mootools 1.11
(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