0
我想在引導中的導航菜單上創建滾動效果,頁面頂部有一個傳送帶,導航菜單位於傳送帶的底部。所以當有人向下滾動時,在他通過導航菜單後,導航菜單將具有navbar-fixed-top類,並且觀看者將看到菜單。 我今天在這個問題上工作,但我找不到解決方案來解決這個問題。 這裏是我的HTML代碼:如何在bootstrap中滾動後創建一個滾動的navbar-fixed-top?
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,700' rel='stylesheet' type='text/css'>
<script src="https://code.jquery.com/jquery.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body class="blog">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="images/3.jpg" alt="slide1" style="width:100%">
<div class="carousel-caption">
<h3>What therefore god has joined together, Let no man seperate.</h3>
<p>– The Bible : Mark 10:9 –</p>
</div>
</div>
<div class="item">
<img src="images/4.jpg" alt="slide2" style="width:100%">
<div class="carousel-caption">
<h3>Lorem Ipsum Header Dolor Sit Amet</h3>
<p>– John Doe –</p>
</div>
</div>
<div class="item">
<img src="images/5.jpg" alt="slide3" style="width:100%">
<div class="carousel-caption">
<h3>Header Slider 3 Caption Text</h3>
<p>– Holy Themeforest : Wordpress Category –</p>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
<header>
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<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" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Our Story</a></li>
<li><a href="#">Time</a></li>
<li><a href="#">Events</a></li>
<li><a href="#">Photos</a></li>
<li><a href="#">Gifts</a></li>
<li><a href="#">From the Blog</a></li>
<li><a href="#">RSVP</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</header>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p><p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<p>Lorem ipsum dolor sit amet</p>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/functions.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
和functions.js:
// =============== Menu setup =============== //
// checks if menu should be fixed
function setup_menu(){
if(!jQuery('body').hasClass('blog') && !jQuery('body').hasClass('single') && !jQuery('body').hasClass('archive') && !jQuery('body').hasClass('search')){
if(!$menu) $menu = jQuery(".navbar");
if (jQuery(window).scrollTop() > 200 && !$menu.hasClass("navbar-fixed-top")){
$menu.addClass("navbar-fixed-top");
} else if(jQuery(window).scrollTop() <= 200 && $menu.hasClass("navbar-fixed-top")) {
$menu.removeClass("navbar-fixed-top");
}
}
// =============== Menu setup END =============== //
另外,我想創建一個滾動的部分,像這樣一個scrollspy效果:http://bit.ly/1hrjDZB我應該怎麼辦這個?