我有用CSS製作的這個小提琴。試圖用jQuery實現不透明度動畫fadeIn/fadeOut
我試圖實現確切動畫使用jQuery fadeIn/fadeOut
。 (沒有不透明度和動畫效果)
stop() and finish()
與fadeIn/fadeOut
一起使用的函數不起作用,因爲如果我快速移動光標,他們只需隱藏或顯示框。
謝謝。
我有用CSS製作的這個小提琴。試圖用jQuery實現不透明度動畫fadeIn/fadeOut
我試圖實現確切動畫使用jQuery fadeIn/fadeOut
。 (沒有不透明度和動畫效果)
stop() and finish()
與fadeIn/fadeOut
一起使用的函數不起作用,因爲如果我快速移動光標,他們只需隱藏或顯示框。
謝謝。
您必須在您的jQuery動畫中使用stop()
來模擬CSS動畫。
它具有以下參數,.stop([clearQueue ] [, jumpToEnd ])
,和你想要的是清除隊列中,而不是直接到終點,所以這將是stop(true, false)
$('.box1').on('mouseenter mouseleave', function(e) {
$('.box2').stop(true, false).animate({opacity: e.type=='mouseenter'? 1 : 0}, 1500)
});
或不透明度
$('.box1').on('mouseenter mouseleave', function() {
$('.box2').stop(true, false).fadeToggle(1500)
});
這裏你去。
http://jsfiddle.net/defmetalhead/Q5cRU/2/
$(".box1").on({
mouseover: function() {
$('.box2').stop().fadeIn('slow');
},
mouseleave: function() {
$('.box2').stop().fadeOut('slow');
}
});
如果將鼠標移開並移開,該動畫會繼續。我想這就是他想要避免的。 –
沒有指定。此外,你只需使用.stop() –
所以,簡單的修復。 IT尚不明確。你只是提到停止() –
@thenewseattle - 這是一個事件處理程序,觸發對的mouseenter和鼠標離開事件,並在進出等等看的方法上來就jQuery的網站,如果你想褪色的元素瞭解更多關於他們如何工作的信息,讓它像CSS動畫一樣工作的相關部分就是stop()方法。 – adeneo
**你是個天才。**非常感謝你! – thenewseattle
謝謝,不客氣! – adeneo