I have looked in the stackoverflow archives but could not find a solution.
The problem is I have a button when mouse is over it, it shows a box beneath it. Now if the mouse moves out of the button the box should hide, but the tricky part comes here. If the mouse leaves the button but remains on the box the box should not hide.
I am using the mouseover and mouseout functions but as soon as the mouse moves out of the button the box hides, even if i try to place the mouse over the box.
(function($) {
$(function() {
var dropDown = $('.box'),
timer,
cartButton = $('.button');
cartButton.hover(function(){
dropDown.slideToggle();
});
});
})(jQuery);
The best way to do this is to wrap both your box and button in a containing element, and bind your hover events to that, instead. Here is a simple demonstration, code here:
HTML:
jQuery:
Because the events are bound on the containing element, the mouse won’t leave it when it moves from the button to the box.
Note that the container is a block element, so takes 100% of the width, so you’ll need to either give it a fixed with,
display: inlineordisplay: inline-block.