2012-08-06 54 views
0

我怎麼解除綁定或通過禁用鼠標它正在徘徊出來之後再重新啓用,如果其他框淡出。禁用鼠標懸停事件那麼reanable

我試圖拆散,但目前看來,它不工作,它只是關閉了整個事情。

我甚至嘗試了超時,但不工作到我的優勢。

任何幫助,將不勝感激,謝謝

$("#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); }); 

回答

2

只是一個猜測嘗試是這樣的:

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

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

這段代碼沒有進行測試,但應該工作。

我認爲你的問題是,你通過mouseover.unbind()作爲一個變量,而不是一個字符串。這就是爲什麼「整個事物」被禁用的原因,因爲JavaScript正在尋找名稱爲mouseover的變量,該變量未定義,導致您的代碼中斷。試試像這樣:.unbind('mouseover')

+0

非常感謝你的解釋和幫助!這正是我想要做的。 – SmileyWar 2012-08-07 09:14:08

+0

@EmmanuelCorwinFlossie請您點擊我答案旁邊的綠色複選標記以接受它,如果您覺得它有幫助。 – 2012-08-07 14:01:20

+0

我很想,但我的代表處是低:( – SmileyWar 2012-08-07 17:43:28

0

不知道這是你正在尋找的algorythm,它是based on answers shown in this question
這裏是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); 
    }); 
}); 

span#miniBasketClose只是一個可選「關閉按鈕」,沒有必要的代碼的功能。其功能可以替代(如果需要),例如也可以將其懸停在某些其他元素上。

+0

你好,謝謝你的答覆,與以前的答案我已經建立了一個關閉按鈕,但謝謝你的答案,這是一個偉大的溶劑。 – SmileyWar 2012-08-07 09:16:25