2013-03-06 31 views
0

撞上了牆,需要一些幫助jQuery的mouseneter和取消綁定

我工作的一個項目,基本上..當你將鼠標懸停在圖片,我需要它「暫停」。當你退出時,它會切換回來。

我有這個工作一次...但因爲我解綁的事件,它只能工作一次。

能引導我走向正確的方向嗎?將不勝感激

這裏是我的代碼片段:

$("#card1").mouseenter(function(){ 
    $("#overlay1").css("z-index","30").show("slide", { direction: "down" }, 700); 
    $("#pope1").css("z-index","30").hide("slide", { direction: "down" }, 700); 
    $(this).unbind("mouseenter") 
}); 

$("#card1").mouseleave(function(){ 

    $("#overlay1").css("z-index","30").hide("slide", { direction: "down" }, 700); 
    $("#pope1").css("z-index","30").show("slide", { direction: "down" }, 700); 
    $(this).unbind("mouseleave") 

}); 

回答

0

我不認爲你一定要取消綁定在這種情況下,任何事件。嘗試改變你的代碼,以這個jsFiddle如何設置:http://jsfiddle.net/CMbQB/

$('div').on('mouseover mouseout', function(e){ 
    if(e.type === "mouseover") { 
     //mouse over events 
    } 
    else if(e.type === "mouseout") { 
     //mouse out events 
    } 
}); 
+0

試過這個..但不能讓它工作不幸... – gregdevs 2013-03-07 02:10:35