I have a jquery animation that is triggered by a mouseenter on the parent () but If the user "wiggles" the mouse on the child () the animation flickers as though it is switching between the mouseout and mouseenter.
The mouseenter is called on the parent. Why is it also attached to the child and can I prevent this?
example:
I've looked into .stopImmediatePropagation(); and .stopPropagation(); I think that may be the right direction but can't quite get the interaction I need.
Thanks.
Use .mouseleave()
instead of .mouseout()
var imgW;
$('.brand-box-item').mouseenter(function(){
if($(this).find('img').is(':animated') === false)
imgW = $(this).find('img').width();
$(this).find('img').stop().animate({'width':'0','margin-left':(imgW/2)+'px'},function(){
$(this).css({'margin-top':'-40px'});
$(this).stop().animate({'width':imgW+'px','margin-left':'0'});
});
});
$('.brand-box-item').mouseleave(function(){
$(this).find('img').stop().animate({'width':'0','margin-left':(imgW/2)+'px'},function(){
$(this).css({'margin-top':'0'});
$(this).animate({'width':imgW+'px','margin-left':'0'});
});
});
"The mouseleave event differs from mouseout in the way it handles event bubbling. If mouseout were used in this example, then when the mouse pointer moved out of the Inner element, the handler would be triggered. This is usually undesirable behavior. The mouseleave event, on the other hand, only triggers its handler when the mouse leaves the element it is bound to, not a descendant. So in this example, the handler is triggered when the mouse leaves the Outer element, but not the Inner element." -jQuery docs