2016-02-17 45 views
0

當我向下滾動我的功能時,他們也有工作。但是我希望他們在回滾到頂端時做相反的事情。但是如何? 這就是我得到的:滾動回頂部做對面

var $document = $(document) 


$document.scroll(function() { 
     if ($document.scrollTop() >= 50) { 
      AnimateFunction(); 
     } 
}); 

function AnimateFunction() { 
    setTimeout(function() { 
    $("#LOGO").animate({height: '180px'}, 1); 
     $("ul").animate({top: '-14px'}, 1); 
     $("li").animate({fontSize: '8pt'}, 1); 
     $("#HB").animate({marginTop: '-10px'}, 1); 
     $("#HB").animate({height: '29px'}, 1).animate({width: '26px'}, 1); 
     } 
    )}; 

我希望有人能幫助我!

回答

0

對於您需要做的幾件事情

到目前爲止,你只檢測文檔上的滾動,並根據滾動條的位置,你正在運行的功能。現在

  1. ,你必須不僅檢測滾動,而且滾動方向see this

  2. 你必須寫恢復您在AnimateFunction功能做了修改另一個函數,當調用它滾動方向向上。在你的新功能中,你會重置這些值。即

    $(「#LOGO」)。animate({height:'originalHeight'},1);

示例代碼

var lastScrollTop = 0; 
$(window).scroll(function(event){ 
    var st = $(this).scrollTop(); 
    if (st > lastScrollTop){ 
     AnimateFunction() 
    } else { 
     AnimateFunctionReverse() 
    } 
    lastScrollTop = st; 
});