views:

27

answers:

1

I have 4 elements that have the same class name that all react when hovered over..

Is there any way to: - Run a function when I am no longer over any of the classes?

Here's what I have-

HTML:

<div class = "item">Hello</div>
<div class = "item">Hi</div>
<div class = "item">Ok</div>
<div class = "item">Wahoo</div>

jQuery:

$('.item').hover(function(e) { 
 $(this).addClass('hover');
 $('.item:not(.hover)').each(function(index) {
  $(this).fadeTo('400', 0.5);
 });
 $('.hover').fadeTo('400', 1);

}, function(e) { 
 $(this).removeClass('hover');
 $('.item').fadeTo('400', .5);
});

Essentially I'm trying to mimic the functionality of: http://labs.dragoninteractive.com/

+1  A: 

This should do the trick.

$('.item').hover(function(e) {
        $('.item').stop().each(function(index) {
                $(this).stop().fadeTo('400', 0.5);
        });
        $(this).stop().fadeTo('400', 1);

}, function(e) {        
        $('.item').stop().fadeTo('400', 1);
});
thephpdeveloper
That won't quite do. This solution will cause everything to fade initially then the it to fadeIn so its not that responsive to a hover. Also I need it to be full opacity when I hover away from it.
Matt
Hi Matt. the trick to responsiveness in such animation is to use stop(). See how i used it in the updated example. works fine now?
thephpdeveloper