Javascript 导航栏不固定

Javascript 导航栏不固定,javascript,html,twitter-bootstrap,css,Javascript,Html,Twitter Bootstrap,Css,嗨,伙计们,我正试图遵循这一点,并为我的网站做完全相同的,但我不能让我的导航栏工作,并按照屏幕下来。我试了很多,但不确定到底发生了什么 HTML: 如果我更改var navHeight=$(窗口).height()-70到277它工作得很好,但是如果我把屏幕缩小,它会在不等待的情况下直接弹出,所以它真的很奇怪 在这件事上有任何帮助都会很好 谢谢,抱歉。我试图修复你的代码,而不是给你一个不同的解决方案。这项工作没有跳跃 var $window = $(window), $el =

嗨,伙计们,我正试图遵循这一点,并为我的网站做完全相同的,但我不能让我的导航栏工作,并按照屏幕下来。我试了很多,但不确定到底发生了什么

HTML:

如果我更改
var navHeight=$(窗口).height()-70
277
它工作得很好,但是如果我把屏幕缩小,它会在不等待的情况下直接弹出,所以它真的很奇怪

在这件事上有任何帮助都会很好


谢谢,抱歉。我试图修复你的代码,而不是给你一个不同的解决方案。这项工作没有跳跃

var $window = $(window),
        $el = $('nav'),
        elTop = $el.offset().top;

      $window.scroll(function() {
        $el.toggleClass('navbar-fixed-top', $window.scrollTop() > elTop);
      });

我注意到你还没有链接到bootstrap js文件-可能与此相关,因为一些功能是在js文件中实现的。尝试过,但仍然不起作用当我将数字更改为70时,它对小屏幕非常有效,如果我更改为277,它对大屏幕非常有效,但对小屏幕不起作用
    body {
        font-family: 'Open Sans', sans-serif, Arial;
        font-size: 16px;
        color: #6D6D6D;
        background-color: #F5F5F5;
        font-weight: 300;
    }
    
    h1,h2,h3,h4,h5,h6 {
        font-family: 'Montserrat', sans-serif, Arial;
        padding-bottom: 5px;
        color: #373432;
        line-height: 1em;
        font-weight: normal;
    }
    
    a {
        text-decoration: none;
        outline: none;
    }
    
    /* Header  */
    .parallax {
        background-image: url("../Images/back1.jpg");
        min-height: 700px;
        background-attachment: fixed;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
        padding: 100px 20px;
    }
    
    .avater {
        width: 260px;
        height: 260px;
        border-radius: 50%;
        position: relative;
        cursor: default;
        box-shadow: inset 0 0 0 0 rgba(200, 95, 66, 0.4), inset 0 0 0 16px rgba(255, 255, 255, 0.16), 0 1px 2px rgba(0, 0, 0, 0.1);
        margin: 0 auto;
        
    }
    
    .info1 {
        text-align: center;
        margin-top: 40px;
    }
    
    .info1 > h1 {
        font-size: 60px;
        color: #FFFFFF;
    }
    
    .info1 > h2 {
        color: #FFFFFF;
        font-size: 30px;
    }
    
    
    /* Navbar  */
    
.fixed {
    position: fixed; 
    top: 0; 
    height: 70px; 
    z-index: 1;
}
.navbar {
    margin-bottom: 0px;
    left: 0;
    top: 0;
    width: 100%;
    list-style: none;
    height: 70px; 
}
.navbar-nav {
    float: none;
    margin: 0;
    text-align: center;
}
.navbar-nav > li {
    float: none;
    display: inline-block;
}
.navbar-nav > li > a {
    line-height: 38px;
}
.navbar-nav > li > a.active {
    background-color: #E7E7E7;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
    color: #333333;
    background-color: #E7E7E7;
}

.navbar-toggle {
    background-color: #000000;
    background-image: none;
    border-radius: 4px;
    float: right;
    margin-bottom: 8px;
    margin-right: 15px;
    margin-top: 18px;
    padding: 9px 10px;
    position: relative;
    
}
.navbar-inverse .navbar-toggle .icon-bar {
    background-color: #2DCC70;
}
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
    background-color: #000000;
}
.navbar-inverse .navbar-collapse,
.navbar-inverse .navbar-form {
    border-color: transparent;
}
    
    .section{
        background-color:Red;
        height: 1000px;
        margin: 0;
    }
    
    .section h1 {
        margin: 0;
    }
    
    .section2{
        background-color:blue;
        height: 1000px;
            margin: 0;
    }
    
    .section3{
        background-color:Black;
        height: 1000px;
            margin: 0;
    }
var $window = $(window),
        $el = $('nav'),
        elTop = $el.offset().top;

      $window.scroll(function() {
        $el.toggleClass('navbar-fixed-top', $window.scrollTop() > elTop);
      });