Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header class="header">
  <div class="container">
    <div class="logo"><a href="#">Logo</a></div>
    <nav>
      <ul>
        <li><a href="#">About</a></li>
        <li><a href="#">Portfolio</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </nav>
  </div>
</header>
<div class="main-container">
  <section class="hero-banner">
    <div class="container">
      <h2>Animated Header On Scroll</h2>
    </div>
  </section>
  <section class="about">
    <div class="container">
      <h2>About</h2>
      <p>"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder
        of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who
        loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious
        physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?" "At vero
        eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia
        animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda
        est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis
        voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
    </div>
  </section>
  <section class="portfolio">
    <div class="container">
      <h2>Portfolio</h2>
      <p>"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder
        of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who
        loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious
        physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?" "At vero
        eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia
        animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda
        est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis
        voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
    </div>
  </section>
</div>
              
            
!

CSS

              
                *{
  margin:0;
  padding:0;
  box-sizing:border-box;
}
img{
  max-width:100%;
}
h2{
  font-size:2.5em;
}
.container{
  width:90%;
  margin:auto;
}
header{
  color:#fff;
  position:absolute;
  display:flex;
  flex-flow: row wrap;
  width:100%;
  top:0;
  left:0;
  z-index:9;
}
header .container{
  display:flex;
  flex-flow: row wrap;
  align-items:center;
  padding:15px 0;
}
.logo{
  font-size:20px;
  text-transform:uppercase;
  font-weight:bold;
}
.logo a{
  color:#fff;
  text-decoration:none;
}
nav {
    justify-content: flex-end;
    display: flex;
    flex: 2 auto;
}
nav ul{
  list-style:none;
  padding:0;
  margin:0;
  display:flex;
  flex-direction: row;
}
nav ul li{
  padding:0.5em;
}
nav ul li a{
  color:#fff;
  text-decoration:none;
  display:inline-block;
}
section{
  padding:150px 0;
}
.hero-banner{
background:url(https://images.unsplash.com/photo-1517946264308-1a7ea8abb6e0?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=add9d7ca772d122fb699bb1790d89a93) no-repeat center center;
  background-size: cover;
  height:100vh;
  display:flex;
  align-items:center;
  text-align:center;
  position:relative;
  z-index:0;
}
.hero-banner:after{
  content:"";
  display:block;
  background:rgba(0,0,0,0.5);
  left:0;
  top:0;
  height:100%;
  width:100%;
  position:absolute;
}
.hero-banner h2{
  color:#fff;
  position:relative;
  z-index:1;
}
.about{
  text-align:center;
  line-height:2;
}
.portfolio{
  text-align:center;
  line-height:2;
  background:#f1f1f1;
}
header.fixed {
  background: #fff;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  opacity:0;
  visibility:hidden;
  box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.2);
  transform:translate(0, -200px);
}
header.fixed nav a, header.fixed .logo a{
  color:#333;
}
header.in-view{
  opacity:1;
  visibility:visible;
  transition: all 0.3s ease;
  transform:translate(0, 0);
}
@media only screen and (max-width: 640px) {
  header.fixed{
    position:relative;
  }
}

              
            
!

JS

              
                $(window).scroll(function() {
  var header = $(document).scrollTop();
  var headerHeight = $(".header").outerHeight();
  var firstSection = $(".main-container section:nth-of-type(1)").outerHeight();
  if (header > headerHeight) {
    $(".header").addClass("fixed");
  } else {
    $(".header").removeClass("fixed");
  }
  if (header > firstSection) {
    $(".header").addClass("in-view");
  } else {
    $(".header").removeClass("in-view");
  }
});
              
            
!
999px

Console