views:

406

answers:

1

I am trying to create an effect where if you hover over an img, the color of text will change below it. And also, when you mouseout, the color will change back to its original color. The page is: http://vitaminjdesign.com/work.html

My code is:

    if(window.jQuery){jQuery(function(){

        (function(){ jQuery('div#one img').bind('mouseover', function(event, ui){var target = jQuery('div#one h2'); target.animate({'color':'#111111'},250,'linear')});})();

    })};

I repeated this about 15 times in a page, and it seems to be pretty buggy, and not smooth. Playt around with it for a minute. Is there a better way of going about this?

+1  A: 

Try using hover, the benefit being that you can specify the mousein and mouseout events in the same function. If you need any help with specifically how to apply what you've got to the hover event, just comment and I'll see what I can do.

EDIT:

Ok, the code on your site already has this

//On mouse over those thumbnail
$('.zitem').hover(function() {

 //Set the width and height according to the zoom percentage
 width = $('.zitem').width() * zoom;
 height = $('.zitem').height() * zoom;

 //Move and zoom the image
 $(this).find('a img').stop(false,true).animate({'width':width, 'height':height, 'top':move, 'left':move}, {duration:200});

 //Display the caption
 $(this).find('div.caption').stop(false,true).fadeIn(200);
},
function() {
 //Reset the image
 $(this).find('a img').stop(false,true).animate({'width':$('.zitem').width(), 'height':$('.zitem').height(), 'top':'0', 'left':'0'}, {duration:100}); 

 //Hide the caption
 $(this).find('div.caption').stop(false,true).fadeOut(200);
});

I'm going to add two lines into this code that do what you want

//On mouse over those thumbnail
$('.zitem').hover(function() {

 //Set the width and height according to the zoom percentage
 width = $('.zitem').width() * zoom;
 height = $('.zitem').height() * zoom;

 //Move and zoom the image
 $(this).find('a img').stop(false,true).animate({'width':width, 'height':height, 'top':move, 'left':move}, {duration:200});

 //Change the header colour
 $(this).siblings('h2').animate({'color':'#111111'},250,'linear');

 //Display the caption
 $(this).find('div.caption').stop(false,true).fadeIn(200);
},
function() {
 //Reset the image
 $(this).find('a img').stop(false,true).animate({'width':$('.zitem').width(), 'height':$('.zitem').height(), 'top':'0', 'left':'0'}, {duration:100}); 

 //Change the header colour back
 $(this).siblings('h2').animate({'color':'#EE4E07'},250,'linear');

 //Hide the caption
 $(this).find('div.caption').stop(false,true).fadeOut(200);
});

That should do it

Gausie
yes, thank, i thought you could do that. I do need help, think you can generate the line of code and i can replicate it? Thanks so much
JCHASE11
Ok. There are a few other things I'm going to do to fix it up. I'll post it when I'm done, in about 5 minutes
Gausie
See my edit to find the solution.
Gausie
wow, much gratitude
JCHASE11