Navbar隐藏div

时间:2017-01-07 19:24:13

标签: javascript jquery css twitter-bootstrap-3

我的导航栏隐藏了应该位于其上方的div

不是我自己的完整副本,但这里是fiddle

HTML:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Burger Corner</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/scrolling-nav.css" rel="stylesheet">
    <link rel="icon" href="images/favicon.png" type="image/x-icon">

</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
    <!-- NAVBAR -->
    <nav class="navbar  navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
<!--                <a class="navbar-brand page-scroll" href="#page-top">Burger Corner</a>-->
                <img src="images/logo.png" width="90" height="60">
            </div>

            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <ul class="nav navbar-nav navbar-right main-nav">
                    <li class="hidden"><a class="page-scroll" href="#page-top"></a></li>
                    <li><a class="page-scroll color_animation" href="#intro">Welcome</a></li>
                    <li><a class="page-scroll color_animation" href="#services">About us</a></li>
                    <li><a class="page-scroll color_animation" href="#reservation">Reservation</a></li>
                    <li><a class="page-scroll color_animation" href="#contact">Contact us</a></li>
                    <li><a id="login_lnk"class="page-scroll color_animation" href="#login" data-toggle="modal" >Login</a></li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>
    <!-- Intro Section -->
    <section class="top-title">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <h1>Burger Corner</h1>
                </div>
            </div>
        </div>
    </section>

    <section id="intro" class="intro-section">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <h1>Welcome section</h1>
                </div>
            </div>
        </div>
    </section>

    <!-- About Section -->
    <div id="wall_1" class="image"></div>
    <section id="about" class="about-section">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <h1>About Section</h1>
                </div>
            </div>
        </div>
    </section>

有问题的div的CSS和有效的CSS:

.top_title{
    font-family: 'Playball', cursive;
/*    background-image: url(../images/intro.jpg) no-repeat center center;*/
    background-size: cover;
    width: 100%;
    height: 100px;
    background-color:#990000;
    text-align:center;
    padding-top: 150px;
}

.intro-section {
    height: 100%;
    padding-top: 150px;
    text-align: center;
    background: #fff;
    z-index: 1;
}

导航栏的CSS:

.color_animation {
    text-decoration: none;
    margin-right: -5px;
    margin-left: -5px !important;
    color: white !important;
    -webkit-transition: color 0.3s ease-out;
    -moz-transition: color 0.3s ease-in-out;
    -o-transition: color 0.3s ease-in-out;
    -ms-transition: color 0.3s ease-in-out;
    transition: color 0.3s ease-in-out;
}
.color_animation:hover{
    color: #990000 !important;
}    

.main-nav a {
        font-size: 20px;
        font-weight: 700;
        text-decoration: none;
        color: #000;
        display: block;
        text-align: center;
        padding: 2px 0;
        transition: color 0.3s ease-in-out;
}

.main-nav {
        padding: 0;
       /*margin:  auto 0 auto;*/ 
}    

    li{
    color: white !important;
    word-spacing: 5px !important;
}

额外的CSS:

body {
    width: 100%;
    height: 100%;
}

html {
    width: 100%;
    height: 100%;
}

@media(min-width:767px) {
    .navbar {
        padding: 20px 0;
        -webkit-transition: background .5s ease-in-out,padding .5s ease-in-out;
        -moz-transition: background .5s ease-in-out,padding .5s ease-in-out;
        transition: background .5s ease-in-out,padding .5s ease-in-out;
    }

    .top-nav-collapse {
        padding: 0;
    }
}

我甚至尝试使用intro-section类并对其进行修改,更改了名称并添加了一些代码,但它确实无法正常工作。navbar隐藏它,它没有我告诉它的背景甚至是height

我让navbar只是为了测试而隐身,你可以看到div在navbar之下,橙色部分就是我说的css并修改了它

1 个答案:

答案 0 :(得分:0)

我认为您的代码没有CSS解决方案。您可以通过删除或添加navbar-fixed-top类来检查滚动位置以使导航栏固定并恢复静态,如下所示:

 $(window).scroll(function() {
   if ($(window).scrollTop() > 50) {
     $('.navbar').addClass('navbar-fixed-top');
   }
   if ($(window).scrollTop() < 51) {
     $('.navbar').removeClass('navbar-fixed-top');
   }
 });

更新了 FIDDLE