How TO - Slide Down a Bar on Scroll
Learn how to slide down a navigation bar on scroll with CSS and JavaScript.
How To Slide Down a Bar
Step 1) Add HTML:
Create a navigation bar:
Example
<div id="navbar">
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
</div>
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
</div>
Step 2) Add CSS:
Style the navigation bar:
Example
#navbar {
background-color: #333; /* Black background color */
position: fixed; /* Make it stick/fixed */
top: -50px; /* Hide the navbar 50 px outside of the top view */
width: 100%; /* Full width */
transition: top 0.3s; /* Transition effect when sliding down (and up) */
}
/* Style the navbar links */
#navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 15px;
text-decoration: none;
}
#navbar a:hover {
background-color: #ddd;
color: black;
}
background-color: #333; /* Black background color */
position: fixed; /* Make it stick/fixed */
top: -50px; /* Hide the navbar 50 px outside of the top view */
width: 100%; /* Full width */
transition: top 0.3s; /* Transition effect when sliding down (and up) */
}
/* Style the navbar links */
#navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 15px;
text-decoration: none;
}
#navbar a:hover {
background-color: #ddd;
color: black;
}

