/*------------------------------------------------------------------
SCROLLING.JS
-------------------------------------------------------------------*/
// Scrolling animation - anchor buttons
$(document).ready(function() {
$(".scrollTo").click(function() {
var t = $(this).attr("href");
$('.active').removeClass('active');
$('#site-header').toggleClass('spy-active');
$("html, body").animate({
scrollTop: $(t).offset().top - 50
}, {
duration: 1e3,
});
setTimeout(function() {
$('#site-header').toggleClass('spy-active');
}, 1e3);
$('body').scrollspy({
target: '.spy-active',
offset: 75
});
$(this).parent().addClass('active');
return false;
});
});
//navbar
var distance = $('#site-header').offset().top,
$window = $(window);
$window.scroll(function() {
if ($window.scrollTop() >= distance) {
$('#site-header').addClass('fixed-nav')
}
if ($window.scrollTop() <= distance) {
$('#site-header').removeClass('fixed-nav')
}
});
$('body').scrollspy({
target: '.navbar',
offset: 74
});
#site-header {
background: #fff;
border-bottom: 1px solid #c6c6c6;
border-top: 1px solid #c6c6c6;
z-index: 1000;
left: 0;
right: 0;
padding: 0;
}
#site-header .navbar {
border: 0;
}
#site-header .navbar-nav {
width: 100%;
text-align: center;
}
#site-header .navbar-nav > li {
float: none;
display: inline-block;
width: 16.66666%;
}
#site-header .navbar-nav li {
border-left: 1px solid #c6c6c6;
}
#site-header .accessibility {
position: absolute;
right: -9999px;
}
#site-header .navbar {
margin-bottom: 0px;
}
#site-header .navbar-nav {
height: 74px;
}
#site-header .navbar-nav > li > a {
position: relative;
height: 74px;
line-height: 55px;
color: #4b4b4c;
font-family: 'montserratregular', Helvetica, sans-serif;
font-size: 1em;
-webkit-transition: background-color 300ms linear;
transition: background-color 300ms linear;
padding-top: 15px;
}
#site-header .commu {
border-right: 1px solid #c6c6c6;
}
#site-header .navbar-nav > li > a:hover,
#site-header .navbar-nav > li > a:focus {
background-color: white;
color: #e55240;
position: relative;
}
#site-header .navbar-toggle {
margin-top: 15px;
}
#site-header .navbar-collapse {
background-color: white;
padding-right: 0;
}
#site-header .navbar-nav > li > a:hover .fa-plus,
#site-header .navbar-nav > li > a:focus .fa-plus {
color: #e55240;
}
#site-header .before-icon {
margin-right: 24px;
}
#site-header .navbar-right {
margin-right: 0px;
}
#site-header .fa-plus {
color: #e55240;
-webkit-transform: rotate(-7deg);
-ms-transform: rotate(-7deg);
transform: rotate(-7deg);
font-size: 25px;
margin-top: 10px;
position: absolute;
top: 22px;
-webkit-transition: 0.5s;
transition: 0.5s;
}
#site-header.fixed-nav {
position: fixed;
top: 0;
}
#site-header.fixed-nav .navbar-nav {
height: 50px;
-webkit-transition: 0.6s;
transition: 0.6s;
}
#site-header.fixed-nav .navbar-nav > li > a {
height: 50px;
line-height: 26px;
-webkit-transition: 0.6s;
transition: 0.6s;
}
.fixed-nav + div {
margin-top: 74px;
}
.menu-button:hover:before,
.menu-button:focus:before,
.menu-button:active:before {
left: 0;
right: 0;
}
.active a:before {
left: 0!important;
right: 0!important;
}
.active a {
color: #fff !important;
background: red !important;
}
#site-header.fixed-nav {
position: fixed;
top: 0;
}
#site-header.fixed-nav .navbar-nav {
height: 50px;
-webkit-transition: 0.6s;
transition: 0.6s;
}
#site-header.fixed-nav .navbar-nav > li > a {
height: 50px;
line-height: 26px;
-webkit-transition: 0.6s;
transition: 0.6s;
}
.fixed-nav + div {
margin-top: 74px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<header id="site-header" class="field-master">
<div class="container">
<div class="navbar navbar-default normal">
<div class="navbar-header">
<a href="#" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
</div>
<div id="spynav" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#Menu1" class="menu-button scrollTo">Menu1</a>
</li>
<li><a href="#Menu2" class="menu-button scrollTo">Menu2</a>
</li>
<li><a href="#Menu3" class="menu-button scrollTo">Menu3</a>
</li>
<li><a href="#Menu4" class="menu-button scrollTo">Menu4</a>
</li>
<li><a href="#Menu5" class="menu-button scrollTo">Menu5</a>
</li>
</ul>
</div>
</div>
</div>
</header>
<div id="Menu1">
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis
elit sit amet quam. Vivamus pretium ornare est.</p>
</blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
\t display: block;
\t width: 300px;
\t height: 80px;
}
</code></pre>
</div>
<div id="Menu2">
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis
elit sit amet quam. Vivamus pretium ornare est.</p>
</blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
\t display: block;
\t width: 300px;
\t height: 80px;
}
</code></pre>
</div>
<div id="Menu3">
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis
elit sit amet quam. Vivamus pretium ornare est.</p>
</blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
\t display: block;
\t width: 300px;
\t height: 80px;
}
</code></pre>
</div>
<div id="Menu4">
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis
elit sit amet quam. Vivamus pretium ornare est.</p>
</blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
\t display: block;
\t width: 300px;
\t height: 80px;
}
</code></pre>
</div>
<div id="Menu5">
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis
elit sit amet quam. Vivamus pretium ornare est.</p>
</blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
\t display: block;
\t width: 300px;
\t height: 80px;
}
</code></pre>
</div>
是的,我關掉scrollspy,因爲我不想被高亮顯示每個菜單項中滾動時,就像在你的榜樣!對不起 –
我貼錯了鏈接,這將工作 https://jsfiddle.net/bfc9x2n7/3/ – Pawel
我明白了,這個工程是聰明的,但唯一的問題是我還是想點擊的鏈接有積極的風格,同時滾動,就像我在我的文章中的第一個例子 –