2015-12-03 46 views
0

我有一個固定的導航,我正在改變徽標的大小在155px滾動高度和改變李的位置。一切都很完美,但是當我回滾時它不會重置。我需要爲此做出更大的功能嗎?任何建議表示歡迎,感謝:)如何在滾動備份時重置scrollTop()div定位?

這裏是jQuery的:

$(document).scroll(function(){ 
      if ($(this).scrollTop()>155){ 
       $('.logo-nav').stop().animate({ height: 70 },20); 
      } else { 
       $(".menu li").addClass("nav-scroll"); 
       $('.logo-nav').stop().animate({ height: 145 },20); 
      } 
     }); 

這裏的CSS:

li { 
    display: inline-block; 
    margin: 0; 
    position: relative; 
    top: 45px; 
    -webkit-transition: all .4s ease; 
    -moz-transition: all .4s ease; 
    -o-transition: all .4s ease; 
    transition: all .4s ease; 
} 
.nav-scroll { 
    top: auto; 
} 

回答

4

使用$(window)而不是$(document)

$(window).scroll(function() { 
    if ($(this).scrollTop() > 155){ 
     $('.logo-nav').stop().animate({ height: 70 },20); 
    } else { 
     $(".menu li").addClass("nav-scroll"); 
     $('.logo-nav').stop().animate({ height: 145 },20); 
    } 
}); 

並確保您將其包含在$(document).ready()函數中。

+0

我嘗試過,但它仍然沒有重置,我錯過了什麼? – jgb

+0

@jgb你能向我們展示一個工作小提琴,這樣我們可以玩嗎? –

+0

這裏是現在的網站:http://toddtalbot.staging.wpengine.com/ – jgb