2012-08-15 67 views
0

我有以下代碼:懸停事件,元件出現故障,但沒有達到對鼠標離開

$(document).on('hover', '.tic_cont:not(.disabled_ticket)',function() { 
     $(this).stop().find(".tic_icon").animate({ top: '-=16px' }, 250); 
     $(this).stop().find(".ti_shd").animate({ opacity: '0.25' }, 250); 
    }, function() { 
     $(this).stop().find(".tic_icon").animate({ top: '+=16px' }, 250); 
     $(this).stop().find(".ti_shd").animate({ opacity: '1' }, 250); 
    }); 

當鼠標移到div必須往下走,而當鼠標離開上去。問題在於div總是停機。問題在哪裏?
謝謝。
UPDATE

在調試器中,我看到第一個函數調用沒有。

+1

請創建一個http://jsfiddle.net/演示。它可以幫助我們幫助你! – 2012-08-15 04:52:07

回答

3
$(document).on('mouseenter', '.tic_cont:not(.disabled_ticket)',function() { 
    $(this).stop().find(".tic_icon").animate({ top: '-=16px' }, 250); 
    $(this).stop().find(".ti_shd").animate({ opacity: '0.25' }, 250); 
}.on('mouseleave', '.tic_cont:not(.disabled_ticket)', function() { 
    $(this).stop().find(".tic_icon").animate({ top: '+=16px' }, 250); 
    $(this).stop().find(".ti_shd").animate({ opacity: '1' }, 250); 
}); 

棄用的jQuery 1.8:作爲字符串「的mouseenter鼠標離開」的縮寫名字「懸停」。它爲這兩個事件附加一個事件處理程序,處理程序必須檢查event.type以確定該事件是mouseenter還是mouseleave。不要將「懸停」僞事件名稱與接受一個或兩個函數的.hover()方法混淆。http://api.jquery.com/on