The CODE
function wkHover(){
$('.worksItem').hover(function() {
$(this).animate({ top: '-10px' }, 300, 'swing', {queue: false});
$('.worksItem').not(this).animate({ opacity: '0.5' }, 300, 'swing', {queue: false});
}, function(){
$(this).animate({ top: '0' }, 200, 'swing', {queue: false});
$('.worksItem').animate({ opacity: '1' }, 200, 'swing', {queue: false});
});
}
All right so I have two problems:
-
When hovering between items, it naturally triggers the mouseout function when going over the margins, which creates this unpleasant flashy effect. What I want to do is just animate the ones being hovered out of and hovered in to so that the rest will stay the same. Any ideas?
-
Try moving the mouse quickly around all of the elements, and try not to go into an epileptic seizure. Anyway to prevent this?
Here is a working fiddle. The key is to
.stop()the animation before adding a new one to the queue:However; this causes problems because multiple animations have to be run at once, so calling
.stop()would interfere with the wrong animation. Therefore the different animations will have to be put in different animationqueues:If you use a different queue from the default (
fx), you have to.dequeue()them manually.[Edit] As for the first problem, I think the best solution is to
.delay()the fade-out animation, to give the cursor some time to move on to the next block. Here is a fiddle with that included:This has some downsides, mainly due to the fact that
.stop()does not cancel timeouts that were set by.delay(). My best solution is to have you choose between the “flash-effect” from the first fiddle, or the delayed fade-in effect from the second fiddle.