2
我想讓我的固定導航淡入,一旦我的內容區域從窗口頂部50px。我已經完成了它的工作,但是我在動畫中出現了一個奇怪的「反彈」。菜單完全出現,然後再次隱形並淡入。任何想法?這裏是我的代碼:jQuery:淡入固定導航當滾動過去某個點
$(window).bind('scroll',function() {
var vPos = $(window).scrollTop(); //The current scroll bar position
var totalH = $('.content').offset().top; // Distance content from top
var finalSize = totalH - vPos; // Get the difference of the distances
console.log(finalSize);
if(finalSize <= 50) {
$('.sticky').fadeIn(300);
} else {
$('.sticky').fadeOut(300);
}
});
可以在這裏看到:http://portfolio.stvartak.net/redesign
謝謝!
還有口吃對我和動畫並不順利。基本上,if語句只能運行一次。問題在於它在第二次觸摸滾輪時再次運行,這會中斷動畫。有沒有辦法讓它只運行一次? 請注意,我無法使用.unbind('scroll'),因爲我的視差背景需要保持綁定才能滾動。謝謝! – user1639227