0
這裏是爲了說明一個小提琴: http://jsfiddle.net/wVRtL/哈弗動畫未完成
HTML:
<section class="full-w blue">
<div class="container">
<div class="three"></div>
<div class="two"></div>
</div>
</section>
<section class="full-w red">
<div class="container">
<div class="two"></div>
<div class="three"></div>
</div>
</section>
jQuery的
$('.full-w').hover(function() {
marginTopHero = $(this).find('.two').css("margin-top").replace("px", "");
newMargin = marginTopHero - 50 + "px";
oldMargin = marginTopHero + "px";
$(this).find('.two').stop().animate({ 'margin-top': newMargin }, 'fast');
}, function() {
$(this).find('.two').stop().animate({ 'margin-top': oldMargin }, 'fast');
});
預期的行爲是當鼠標懸停在行上時,黃色矩形向上移動,並在鼠標離開行時向下移動到其原始位置。但是,如果將指針從一條紅線快速移動到另一條紅線,您會發現黃色框逐漸擡起,直到它碰到線的頂端。
我需要檢索該元件的上邊距值,以便能夠恢復到上鼠標離開那個位置
I(所述邊距將從一個。二變化到另一個)明白這是一個棘手的問題,除非我完全錯過了一些東西。
謝謝!
嗯......好像沒有被不幸地工作。 – jonasll 2013-05-02 17:44:49
我認爲問題在於每次出現懸停時我都會檢索margin-top,而我應該只存儲第一個實例。 – jonasll 2013-05-02 17:45:49