2017-08-04 64 views

回答

0

所以,

如果我理解你的问题,你希望用户开始滚动后,导航栏固定到顶部。那么,这里是我的这个实现...我用这个答案https://stackoverflow.com/a/21301875并修改它为这种情况以及记录的代码。

Codepen

/** 
* Scroll management 
*/ 
$(document).ready(function() { 

    // Define the menu we are working with 
    var menu = $('.navbar.navbar-default.navbar-inverse'); 

    // Get the menus current offset 
    var origOffsetY = menu.offset().top; 

    /** 
    * scroll 
    * Perform our menu mod 
    */ 
    function scroll() { 

     // Check the menus offset. 
     if ($(window).scrollTop() >= origOffsetY) { 

      //If it is indeed beyond the offset, affix it to the top. 
      $(menu).addClass('navbar-fixed-top'); 

     } else { 

      // Otherwise, un affix it. 
      $(menu).removeClass('navbar-fixed-top'); 

     } 
    } 

    // Anytime the document is scrolled act on it 
    document.onscroll = scroll; 

}); 
+0

谢谢先生,我还可以在导航栏中使用css过渡吗? –

0

附加容器流体的3线

<div class="container-fluid"> 
在第5行

<nav class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation"> 

codepen

添加导航栏固定顶部看到你的答案被覆盖存在的文件。 http://getbootstrap.com/components/#navbar

学英语如果打扰你