2010-08-28 93 views
2

我正在使用Jquery隱藏顯示div。我想在「。微博發貼器」懸停並隱藏時不顯示該div。完成了第一部分,但不能在沒有徘徊時隱藏它。如何在不再懸停時隱藏div

$(".microblogpostwrapper").hover(function(){ 
      $(this).find(".microblogpostactions").show(); 
           }); 

回答

4

.hover()處理程序將觸發一次mouseenter和一次mouseleave

$(".microblogpostwrapper").hover(function(){ 
    $(this).find(".microblogpostactions").toggle(); // Toggle the show/hide 
}); 

可以確保適當的切換是通過傳遞一個布爾值.toggle()進行:

$(".microblogpostwrapper").hover(function(e){ 
    $(this).find(".microblogpostactions").toggle(e.type == 'mouseenter'); 
}); 

或者,你可以通過第二個功能hover(),你會用.hide()

0

jQuery的.hover()binds two handlers,一個用於 '中',另一個是 '出來。'以下應實現你想要的(雖然它可能是值得分配你操縱的變量略有提高速度的元素):

$(".microblogpostwrapper").hover(
    function(){ 
     $(this).find(".microblogpostactions").show(); 
    }, 
    function(){ 
     $(this).find(".microblogpostactions").hide() 
    } 
); 
0

u可以使用的mouseenter /鼠標離開停止冒泡(再呼叫懸停鼠標時移動):::

$(".microblogpostwrapper").mouseenter(function() { 
    $(this).find(".microblogpostactions").show(); 
}).mouseleave(function() { 
    $(this).find(".microblogpostactions").hide(); 
});​ 
+0

調用懸停是的mouseenter和鼠標離開速記... – 2010-08-28 18:51:53