Skip to content

Instantly share code, notes, and snippets.

@RedWolves
Created May 11, 2010 17:52
Show Gist options
  • Save RedWolves/397601 to your computer and use it in GitHub Desktop.
Save RedWolves/397601 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$("#masthead ul").imageSwap();
});
$.fn.imageSwap = function() {
var $parentElement = this;
var cache = [];
//preload the active images before use.
var imageSrc = $parentElement.find("img").get();
for (var i = imageSrc.length; i--; ) {
var cacheImage = document.createElement('img');
cacheImage.src = imageSrc[i].src.replace("_off", "_on");
cache.push(cacheImage);
}
//Events for mouseover mouseout on the images within the parentElement that was passed in.
$parentElement.find("img").bind("mouseover", function() {
var $img = $(this);
$img.attr("src", $img.attr("src").replace("_off", "_on"));
}).bind("mouseout", function() {
var $img = $(this);
$img.attr("src", $img.attr("src").replace("_on", "_off"));
});
};
@RedWolves
Copy link
Author

Updated plugin to be compatible with jQuery 1.2.6+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment