2010-10-26 15 views
2

當您將鼠標懸停在jQuery中的鏈接上時,我試圖實現很好的淡入淡出效果。使用jQuery在mouseover mouseout上淡化鏈接的顏色

到目前爲止,我有:

$('a').hover(
function() { 
    $(this).animate({ color: '#fff' }, 1000); 
}, 
function() { 
    $(this).animate({ color: '#000' }, 1000); 
}); 

裏面居然沒有工作的罰款。但是,想象一下,如果鏈接是導航,彼此靠近。如果您嘗試從一個鏈接懸停到其旁邊的鏈接,然後回幾次。 這些鏈接會進行精神淡入淡出,如果有動畫已經發生,我將如何阻止正在「排隊」的事件?

任何意見讚賞!

回答

5

您正在尋找的stop功能

$('a').hover(
    function() { 
     $(this).stop().animate({ color: '#fff' }, 1000); 
    }, 
    function() { 
     $(this).stop().animate({ color: '#000' }, 1000); 
    } 
);