【发布时间】:2017-08-18 05:29:33
【问题描述】:
我有标题、导航栏和封面照片。 每当用户向下滚动时,标题就会被隐藏,并且导航栏保持在顶部,这是我想要的方式。但是,当导航栏经过封面照片时,导航栏会消失,但在经过内容时会出现。 我还设置了一个脚本,如果用户向下滚动,它将使导航栏固定在顶部。如果我删除封面照片 html 代码,一切正常。 它有什么问题?
下面是我的代码:
<!--HEADER -->
<div class="header-page">
<a class="navbar-header" href="#">
<img src="images/logo/logo.png" width="300px" height="150px" />
</a>
<a href="" class="navbar-header-text">Login</a> |
<a href="" class="navbar-header-text">Create an account</a>
</div>
<!--NAVBAR -->
<div class="menu">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">LOGO</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</nav>
</div>
<!--COVER PHOTO-->
<div class="start-page parallax-background" id="home">
<div class="opacity"></div>
<div class="content">
<div class="arrow-down"></div>
</div>
</div>
<!--CONTENT-->
<div class="container">
<p> example sentences</p>
</div>
这是我的外部样式表。
/* NAVIGATION BAR */
.menu {
position:absolute;
width:100%;
margin:0;
height: 50px;
}
.navbar {
color:red;
border:none;
border-radius:0;
margin-top:0;
}
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
background: white;
}
.navbar .navbar-collapse {
text-align: center;
background: white;
}
.fixed {
position:fixed;
top:0;
}
.hide-header {
display: none;
}
/* COVER PAGE */
.start-page
{
position:relative;
width:100%;
height:500px;
background:url(../images/cover/cover3.jpg) 0px 0px fixed;
}
.opacity
{
position:absolute;
width:100%;
height:500px;
background:rgba(0,0,0,0.7);
}
.arrow-down
{
position: absolute;
bottom: 110px;
left: 50%;
margin-left: -10px;
width: 21px;
height: 29px;
background: url(../images/icons/arrow-down.png) no-repeat center center;
display: block;
-webkit-animation: bounce-fade 1.2s infinite; /* Safari 4+ */
-moz-animation: bounce-fade 1.2s infinite; /* Fx 5+ */
-o-animation: bounce-fade 1.2s infinite; /* Opera 12+ */
animation: bounce-fade 1.2s infinite; /* IE 10+ */
}
@-webkit-keyframes bounce-fade
{
0% { opacity: 0; bottom: 70px; }
100% { opacity: 1; bottom: 35px; }
}
@-moz-keyframes bounce-fade
{
0% { opacity: 0; bottom: 70px; }
100% { opacity: 1; bottom: 35px; }
}
@-o-keyframes bounce-fade
{
0% { opacity: 0; bottom:70px; }
100% { opacity: 1; bottom: 35px; }
}
@keyframes bounce-fade
{
0% { opacity: 0; bottom: 70px; }
100% { opacity: 1; bottom: 35px; }
}
这是用于导航栏的 Javascript。
var num = 150;
$(window).bind('scroll', function ()
{
if ($(window).scrollTop() > num)
{
$('.menu').addClass('fixed');
//$('.page-header').addClass('hide-header');
}
else
{
$('.menu').removeClass('fixed');
//$('.page-header').removeClass('hide-header');
}
});
【问题讨论】:
-
将
background:white;添加到.fixed类 -
它没有背景
标签: javascript jquery html css