Skip to content

Instantly share code, notes, and snippets.

@bcalloway
Created February 23, 2009 15:38
Show Gist options
  • Save bcalloway/69003 to your computer and use it in GitHub Desktop.
Save bcalloway/69003 to your computer and use it in GitHub Desktop.
jQuery rollover image nav
$(document).ready(function() {
// Preload all rollovers
$("#tabs img").each(function() {
// Set the original src
rollsrc = $(this).attr("src");
rollON = rollsrc.replace(/.jpg$/ig,"2.jpg");
$("<img>").attr("src", rollON);
});
// Navigation rollovers
$("#tabs a").mouseover(function(){
imgsrc = $(this).children("img").attr("src");
matches = imgsrc.match(/2/);
// don't do the rollover if state is already ON
if (!matches) {
imgsrcON = imgsrc.replace(/.jpg$/ig,"2.jpg"); // strip off extension
$(this).children("img").attr("src", imgsrcON);
}
});
$("#tabs a").mouseout(function(){
$(this).children("img").attr("src", imgsrc);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment