views:

916

answers:

3

Hello-

Im creating a nav that uses jquery to replace the image on rollover. Here is the code I am using:

http://peps.ca/blog/easy-image-rollover-script-with-jquery/

basically, you add a suffix (_o) to the filename and when you rollover the src, jquery replaces it with the (_o).png. I want to add fade so when there is a rollover, the transition isn't instant, rather there is a quick, elegant fade. Any ideas?

A: 

You could layer a second (hidden) element over the top of your default image, then see about fading that one in and out with a rollover.

keithjgrant
+1  A: 

rather than replace, you'll have to overlay a new image and fade it in, waiting till the transition has completed.

something like...

$('.my_img').parent().append($('.my_img').clone().attr('src','my_img_o.jpg').fadeIn('slow'))

assuming the element is absolutely positioned

Ben
thanks Ben. Had some trouble doing this. I am trying to make a nav, with 5 images. Each image needs to have a fade-in hover effect. So in that jquery code (http://peps.ca/blog/easy-image-rollover-script-with-jquery/) would I need to delete anything or can I simply use this snippet? Would I need to repeat this 5 times in order? I would really appreciate it if you could tell me the appropriate place for insertion. Thanks a lot. Also ('.my_img') would be replaced with ('image.png') correct?
JCHASE11
+1  A: 
$('#the_image).hover(function() {
   $(this).fadeOut(function() {
     $(this).attr('src', $(this).attr('src').replace(".png", "_o.png")).fadeIn(); 
   });
}, function {
   $(this).fadeOut(function() {
     $(this).attr('src', $(this).attr('src').replace("_o.png", ".png")).fadeIn(); 
   });
});
Scott Evernden