Maybe there's a better way to do this. but I thought I'd try.
I want to write a simple image toggle script that would work with multiple images.
When the user mouses over, change the src, using the data- attribute. Then on mouseout, revert to the original src.
Is this a dumb way to do it?
I got this far. it switches the src, but I'm not sure how to save the original src to revert back on mouseout.
$('.portfolio_thumbs').live('hover', function(){
var thumbnail = $(this).attr("src");
var whichThumb = $(this).data('color');
if ($(thumbnail).attr("src") !== whichThumb){
$(this).attr("src", whichThumb);
} else {
$(this).attr("src", thumbnail);
}
});
The images in the html are like this:
<img src="images/portfolio/Image1.jpg" class="portfolio_thumbs" data-color="images/portfolio/Image1Color.jpg">
<img src="images/portfolio/Image2.jpg" class="portfolio_thumbs" data-color="images/portfolio/Image2Color.jpg">
<img src="images/portfolio/Image3.jpg" class="portfolio_thumbs" data-color="images/portfolio/Image3Color.jpg">