Created
May 11, 2010 17:52
-
-
Save RedWolves/397601 to your computer and use it in GitHub Desktop.
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
$(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")); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated plugin to be compatible with jQuery 1.2.6+