0

How do I unbind or disable the mouse over after it's being hovered out then re-enable if the other box is faded out.

I tried the unbind, but seems that its not working, it just disables the whole thing.

I even tried a timeout but that is not working into my advantage.

Any help would be appreciated.

$("#shopping_basket").mouseover(function() { 
            // set a timeout so that this event will not trigger twice when mouseover from the bottom
            setTimeout(function() {
                /*$("#shopping_basket").unbind(mouseover);*/
                $("#miniBasketDetails").fadeIn(500);
            },500);
            });     
        $("#miniBasketDetails").mouseleave(function() { $("#miniBasketDetails").fadeOut(500); });
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
SmileyWar
  • 25
  • 1
  • 9

2 Answers2

2

Just a guess try something like this:

$("#shopping_basket").bind('mouseover', function() {
  setTimeout(function() {
    $("#shopping_basket").unbind('mouseover');
    $("#miniBasketDetails").fadeIn(500);
  }, 500);

 //Re-enable as needed: $("#shopping_basket").bind('mouseover', function(){});
});

This code is not tested, but should work.

I think your problem was that you passed mouseover into .unbind() as a variable, not a string. This is why the "whole thing" was disabled, because JavaScript was looking for a variable named mouseover, which was not defined, and caused your code to break. Try it like this: .unbind('mouseover').

Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
0

Not sure if this is the algorythm you're looking for, it is based on answers shown in this question.
Here is the fiddle and the code:

$("#shopping_basket").hover(function() {
    $("#miniBasketDetails").fadeIn(500);
}, function() {
    $("#miniBasketDetails").data('is_over', false);
    setTimeout(function() {
        if (!$('#miniBasketDetails').data('is_over')) {
            //if not hovered over the #miniBasketDetails in 650 miliseconds after mouseleave
            $("#miniBasketDetails").fadeOut(500);
        }
    }, 650);
});

$("#miniBasketDetails").mouseenter(function() {
    $(this).data('is_over', true);
});

$('#miniBasketClose').click(function() {
    $("#miniBasketDetails").fadeOut(500, function() {
        $(this).data('is_over', false);
    });
});

The span#miniBasketClose is just one optional "Close button", not necessary for functionality of the code. Its functionality can be substituted (if needed) for example also with hovering over some other elements.

Community
  • 1
  • 1
Stano
  • 8,749
  • 6
  • 30
  • 44
  • Hello there, thanks for the reply, with the previous answer i have actually established a close button, but thanks for the answer this is a great sollution. – SmileyWar Aug 07 '12 at 09:16