Created
February 23, 2009 15:38
-
-
Save bcalloway/69003 to your computer and use it in GitHub Desktop.
jQuery rollover image nav
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() { | |
// 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