有一個演示了here,這裏是我目前的jQuery是jQuery的動畫麻煩
var height1 = $('.spotlight:nth-child(1)').height();
var height2 = $('.spotlight:nth-child(2)').height();
$('.spotlight').each(function() {
var spot = $(this),
caption = $("<div class='caption'></div>").appendTo(spot);
caption.load(spot.data('who') + '.html');
spot.hover(function() {
caption.clearQueue().animate({ top : '-=100px' }, 150)
}, function() {
caption.clearQueue().animate({ top : '+=100px' }, 150)
});
});
$('.spotlight:nth-child(1) .caption').css('top', height1 + 'px');
$('.spotlight:nth-child(2) .caption').css('top', height2 + 'px');
而這一切都工作正常,花花公子,但有,如果你繼續下去,在它的惱人的動畫循環。我嘗試使用.clearQueue()和.stop(),但它們帶有自己的錯誤(如果移動速度太快或太慢)總之呢?
你是什麼意思關於「動畫循環」?在任何情況下,都不確定,但我注意到,如果我在兩個div之間快速移動鼠標,滑動文本最終會停止滑出。我認爲這是因爲你正在使用「 -/+ = 100」,並且當第一個結束之前鼠標觸發另一個事件時,它會將「頂部」數學擰緊,並將文本向下移動。 – ilia 2011-03-11 15:03:45
@Val:藍色的bg確實有懸停...... @ilia:這正是發生了什麼,但我不知道如何解決它。 – Koalatea 2011-03-11 15:10:00
好的是我的壞:)'.stop(true,true)'可能是答案或嘗試並重置頂部的位置到其默認b4'.animate()'並刪除'clearQueue()' – Val 2011-03-11 15:12:57