markdown 顶部滑动导航
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 顶部滑动导航相关的知识,希望对你有一定的参考价值。
* {
box-sizing: border-box;
}
body {
color: #8f8f8f;
background: white;
font-family: "Oswald", serif;
-webkit-font-smoothing: antialiased;
padding: 0;
margin: 0;
}
a {
text-decoration: none;
}
h1 {
font-size: 30px;
line-height: 1.8;
font-family: "Oswald", sans-serif;
}
p {
margin-bottom: 20px;
font-size: 17px;
line-height: 2;
}
.row {
width: 100%;
margin: 0 auto;
position: relative;
padding: 0 2%;
}
.content {
max-width: 940px;
width: 100%;
margin: 0 auto;
padding: 50px 2% 50px;
}
.main_header .row .content {padding: 0;}
.dark {background:#333;}
#hero {
position: relative;
background: #f5f5f5;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
text-align: center;
color: #637076;
padding-top: 110px;
min-height: 500px;
letter-spacing: 2px;
font-family: "Oswald", sans-serif;
}
#hero h1 {
font-size: 50px;
line-height: 1.3;
}
#hero h1 span {
font-size: 25px;
color: #ffffff;
border-bottom: 2px solid #ffffff;
padding-bottom: 12px;
line-height: 3;
}
.main_header {
position: fixed;
top: 0px;
max-height: 70px;
z-index: 999;
width: 100%;
padding-top: 17px;
background: none;
overflow: hidden;
transition: all 0.3s;
opacity: 0;
top: -100px;
padding-bottom: 6px;
font-family: "Oswald", sans-serif;
}
@media only screen and (max-width: 766px) {
.main_header {
padding-top: 25px;
}
}
.open-nav {
max-height: 400px !important;
}
.open-nav .mobile-toggle {
transform: rotate(-90deg);
}
.sticky {
background-color: rgba(255, 255, 255, 0.93);
opacity: 1;
top: 0px;
border-bottom: 1px solid silver;
}
.logo {
width: 170px;
font-size: 25px;
color: #8f8f8f;
text-transform: uppercase;
float: left;
display: block;
margin-top: 0;
line-height: 1;
margin-bottom: 10px;
}
@media only screen and (max-width: 766px) {
.logo {
float: none;
}
}
nav {
float: right;
width: 60%;
}
@media only screen and (max-width: 766px) {
nav {
width: 100%;
}
}
nav ul {
list-style: none;
overflow: hidden;
text-align: right;
float: right;
}
@media only screen and (max-width: 766px) {
nav ul {
padding-top: 10px;
margin-bottom: 22px;
float: left;
text-align: center;
width: 100%;
}
}
nav ul li {
display: inline-block;
margin-left: 35px;
line-height: 1.5;
}
@media only screen and (max-width: 766px) {
nav ul li {
width: 100%;
padding: 7px 0;
margin: 0;
}
}
nav ul a {
color: #888888;
text-transform: uppercase;
font-size: 12px;
border-top: 1px solid transparent;
border-bottom: 1px solid transparent;
transition: all 500ms linear;
}
nav ul a.active {
border-top: 1px solid gray;
border-bottom: 1px solid gray;
transition: all 500ms 100ms linear;
}
.mobile-toggle {
display: none;
cursor: pointer;
font-size: 20px;
position: absolute;
right: 22px;
top: 0;
width: 30px;
transition: all 200ms ease-in;
}
@media only screen and (max-width: 766px) {
.mobile-toggle {
display: block;
}
}
.mobile-toggle span {
width: 30px;
height: 4px;
margin-bottom: 6px;
border-radius: 1000px;
background: #8f8f8f;
display: block;
}
.mouse {
display: block;
margin: 0 auto;
width: 26px;
height: 46px;
background: rgba(255,255,255,0.5);
border-radius: 13px;
border: 2px solid #ffffff;
position: absolute;
bottom: 95px;
position: absolute;
left: 51%;
margin-left: -24px;
}
.mouse span {
display: block;
margin: 6px auto;
width: 2px;
height: 2px;
border-radius: 4px;
background: #ffffff;
border: 1px solid transparent;
animation-duration: 1s;
animation-fill-mode: both;
animation-iteration-count: infinite;
animation-name: scroll;
}
@keyframes scroll {
0% {
opacity: 1;
transform: translateY(0);
}
100% {
opacity: 0;
transform: translateY(20px);
}
}
.scrollup {
color: rgba(0,0,0,0.3);
font-size: 40px;
text-align: center;
line-height: 40px;
width: 40px;
height: 40px;
position: fixed;
display: none;
bottom: 50px;
right: 100px;
}
// Sticky Header
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$('.main_header').addClass('sticky');
} else {
$('.main_header').removeClass('sticky');
}
});
// Mobile Navigation
$('.mobile-toggle').click(function() {
if ($('.main_header').hasClass('open-nav')) {
$('.main_header').removeClass('open-nav');
} else {
$('.main_header').addClass('open-nav');
}
});
$('.main_header li a').click(function() {
if ($('.main_header').hasClass('open-nav')) {
$('.navigation').removeClass('open-nav');
$('.main_header').removeClass('open-nav');
}
});
// navigation scroll
$('nav a').click(function(event) {
var id = $(this).attr("href");
var offset = 0;
var target = $(id).offset().top - offset;
$('html, body').animate({
scrollTop: target
}, 500);
event.preventDefault();
});
/* Scroll-to-Top Button */
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$('.scrollup').fadeIn();
} else {
$('.scrollup').fadeOut();
}
});
$('.scrollup').click(function () {
$("html, body").animate({
scrollTop: 0
}, 600);
return false;
});
/* WORK IN PROGRESS
NAVIGATION ACTIVE STATE IN SECTION AREA
*/
var sections = $('section'), nav = $('nav'), nav_height = nav.outerHeight();
$(window).on('scroll', function () {
var cur_pos = $(this).scrollTop();
sections.each(function() {
var top = $(this).offset().top - nav_height,
bottom = top + $(this).outerHeight();
if (cur_pos >= top && cur_pos <= bottom) {
nav.find('a').removeClass('active');
sections.removeClass('active');
$(this).addClass('active');
nav.find('a[href="#'+$(this).attr('id')+'"]').addClass('active');
}
});
});
<header class="main_header">
<div class="row">
<div class="content">
<a class="logo" href="#">James Driscoll</a>
<div class="mobile-toggle">
<span></span>
<span></span>
<span></span>
</div>
<nav>
<ul>
<li><a href="#sec01">Skills</a></li>
<li><a href="#sec02">Education</a></li>
<li><a href="#sec03">Section 03</a></li>
<li><a href="#sec04">Section 04</a></li>
</ul>
</nav>
</div>
</div> <!-- END row -->
</header>
<div class="sections">
<section id="hero">
<h1>Navigation</h1>
</section><!-- END hero -->
<section class="row dark" id="sec01">
<div class="content">
<h1 >Section 01</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nostrum, recusandae, at, labore velit eligendi amet nobis repellat natus sequi sint consectetur excepturi doloribus vero provident consequuntur accusamus quisquam nesciunt cupiditate soluta alias illo et deleniti voluptates facilis repudiandae similique dolore quaerat architecto perspiciatis officiis dolor ullam expedita suscipit neque minima rem praesentium inventore ab officia quos dignissimos esse quam placeat iste porro eius! Minus, aspernatur nesciunt consectetur. Sit, eius, itaque, porro, beatae impedit officia tenetur reiciendis autem vitae a quae ipsam repudiandae odio dolorum quaerat asperiores possimus corporis optio animi quisquam laboriosam nihil quam voluptatum quidem veritatis iste culpa iure modi perspiciatis recusandae ipsa libero officiis aliquam doloremque similique id quasi atque distinctio enim sapiente ratione in quia eum perferendis earum blanditiis. Nobis, architecto, veniam molestias minus iste necessitatibus est ab in earum ratione eveniet soluta molestiae sed illo nostrum nemo debitis. Minus, quod totam aliquam ea asperiores fugit quaerat excepturi dolores ratione numquam consequatur id unde alias provident vero incidunt exercitationem similique consequuntur hic possimus? Fuga, eveniet quaerat inventore corporis laborum eligendi enim soluta obcaecati aliquid veritatis provident amet laudantium est quisquam dolore exercitationem modi? Distinctio, pariatur, ab velit praesentium vitae quidem consequatur deleniti recusandae odit officiis. Quidem, cupiditate.</p>
</div>
</section><!-- END row -->
<section class="row" id="sec02">
<div class="content">
<h1>Section 02</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nostrum, recusandae, at, labore velit eligendi amet nobis repellat natus sequi sint consectetur excepturi doloribus vero provident consequuntur accusamus quisquam nesciunt cupiditate soluta alias illo et deleniti voluptates facilis repudiandae similique dolore quaerat architecto perspiciatis officiis dolor ullam expedita suscipit neque minima rem praesentium inventore ab officia quos dignissimos esse quam placeat iste porro eius! Minus, aspernatur nesciunt consectetur. Sit, eius, itaque, porro, beatae impedit officia tenetur reiciendis autem vitae a quae ipsam repudiandae odio dolorum quaerat asperiores possimus corporis optio animi quisquam laboriosam nihil quam voluptatum quidem veritatis iste culpa iure modi perspiciatis recusandae ipsa libero officiis aliquam doloremque similique id quasi atque distinctio enim sapiente ratione in quia eum perferendis earum blanditiis. Nobis, architecto, veniam molestias minus iste necessitatibus est ab in earum ratione eveniet soluta molestiae sed illo nostrum nemo debitis. Minus, quod totam aliquam ea asperiores fugit quaerat excepturi dolores ratione numquam consequatur id unde alias provident vero incidunt exercitationem similique consequuntur hic possimus? Fuga, eveniet quaerat inventore corporis laborum eligendi enim soluta obcaecati aliquid veritatis provident amet laudantium est quisquam dolore exercitationem modi? Distinctio, pariatur, ab velit praesentium vitae quidem consequatur deleniti recusandae odit officiis. Quidem, cupiditate.</p>
</div>
</section><!-- END row -->
<section class="row dark" id="sec03">
<div class="content">
<h1>Section 03</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nostrum, recusandae, at, labore velit eligendi amet nobis repellat natus sequi sint consectetur excepturi doloribus vero provident consequuntur accusamus quisquam nesciunt cupiditate soluta alias illo et deleniti voluptates facilis repudiandae similique dolore quaerat architecto perspiciatis officiis dolor ullam expedita suscipit neque minima rem praesentium inventore ab officia quos dignissimos esse quam placeat iste porro eius! Minus, aspernatur nesciunt consectetur. Sit, eius, itaque, porro, beatae impedit officia tenetur reiciendis autem vitae a quae ipsam repudiandae odio dolorum quaerat asperiores possimus corporis optio animi quisquam laboriosam nihil quam voluptatum quidem veritatis iste culpa iure modi perspiciatis recusandae ipsa libero officiis aliquam doloremque similique id quasi atque distinctio enim sapiente ratione in quia eum perferendis earum blanditiis. Nobis, architecto, veniam molestias minus iste necessitatibus est ab in earum ratione eveniet soluta molestiae sed illo nostrum nemo debitis. Minus, quod totam aliquam ea asperiores fugit quaerat excepturi dolores ratione numquam consequatur id unde alias provident vero incidunt exercitationem similique consequuntur hic possimus? Fuga, eveniet quaerat inventore corporis laborum eligendi enim soluta obcaecati aliquid veritatis provident amet laudantium est quisquam dolore exercitationem modi? Distinctio, pariatur, ab velit praesentium vitae quidem consequatur deleniti recusandae odit officiis. Quidem, cupiditate.</p>
</div>
</section><!-- END row -->
<section class="row" id="sec04">
<div class="content">
<h1>Section 04</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nostrum, recusandae, at, labore velit eligendi amet nobis repellat natus sequi sint consectetur excepturi doloribus vero provident consequuntur accusamus quisquam nesciunt cupiditate soluta alias illo et deleniti voluptates facilis repudiandae similique dolore quaerat architecto perspiciatis officiis dolor ullam expedita suscipit neque minima rem praesentium inventore ab officia quos dignissimos esse quam placeat iste porro eius! Minus, aspernatur nesciunt consectetur. Sit, eius, itaque, porro, beatae impedit officia tenetur reiciendis autem vitae a quae ipsam repudiandae odio dolorum quaerat asperiores possimus corporis optio animi quisquam laboriosam nihil quam voluptatum quidem veritatis iste culpa iure modi perspiciatis recusandae ipsa libero officiis aliquam doloremque similique id quasi atque distinctio enim sapiente ratione in quia eum perferendis earum blanditiis. Nobis, architecto, veniam molestias minus iste necessitatibus est ab in earum ratione eveniet soluta molestiae sed illo nostrum nemo debitis. Minus, quod totam aliquam ea asperiores fugit quaerat excepturi dolores ratione numquam consequatur id unde alias provident vero incidunt exercitationem similique consequuntur hic possimus? Fuga, eveniet quaerat inventore corporis laborum eligendi enim soluta obcaecati aliquid veritatis provident amet laudantium est quisquam dolore exercitationem modi? Distinctio, pariatur, ab velit praesentium vitae quidem consequatur deleniti recusandae odit officiis. Quidem, cupiditate.</p>
</div>
</section><!-- END row -->
<!-- Scroll-to-Top -->
<a href="#" class="scrollup"><i class="fa fa-arrow-circle-o-up"></i></a>
</div><!-- END sections -->
Top Sliding Nav
---------------
Hidden nav that slides in from the top once the page is scrolled.
Update: Added Active state to current navigation section. Changed each of the <div> wrappers to <section> and added a ".sections" wrapper.
Forked from [Chris Gruber](http://codepen.io/cgruber/)'s Pen [Top Sliding Nav](http://codepen.io/cgruber/pen/kotqf/).
A [Pen](http://codepen.io/JamesDriscoll/pen/XJJwrZ) by [James Driscoll](http://codepen.io/JamesDriscoll) on [CodePen](http://codepen.io/).
[License](http://codepen.io/JamesDriscoll/pen/XJJwrZ/license).
以上是关于markdown 顶部滑动导航的主要内容,如果未能解决你的问题,请参考以下文章