2015-10-26 157 views
-1

我試圖實現類似的東西here修復導航欄上向下滾動

但對我來說它不是在滾動放低。請提供任何例子或資源來實現這一功能,在頂部固定。

 .features-switcher.fixed:after, 
     { 
     -webkit-backface-visibility: hidden; 
     backface-visibility: hidden; 
     -webkit-transform: translate3d(0, 0, 0); 
     transform: translate3d(0, 0, 0); 
     position: fixed; 
     z-index: 101; 
     width: 100%; 
     height: 65px; 
     top: 0; 
     left: 0; 
     opacity: 1 
    } 

對於我的導航欄的div類features-switcher

 $(window).scroll(function() { 
      console.log("scrolled down"); 
      console.log($(window).scrollTop()); 
      if ($(window).scrollTop() > 150) { 
       $('features-switcher').css('top', 0); 
      } 
     } 
     );  
+0

你能提供一些代碼嗎?你有什麼嘗試?它在哪裏失敗? –

+0

添加了代碼..我嘗試使用css:標記後 – djkp

+2

我會使用javascript來檢測滾動事件,當'window.scrollTop'高於你需要設置的CSS'position:fixed;'(以及'top'和其他屬性)添加到您的導航欄中,並在'window.scrollTop'小於此值時設置其他CSS。 –

回答

0

你缺少一個.

$('features-switcher').css('top', 0);

應該是...

$('.features-switcher').css('top', 0);

相關問題