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

Save Automatically?

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

              
                <nav id="nav">
  <h1>Parallax</h1>
  <div class="ham">
    <span class="bar1"></span>
    <span class="bar2"></span>
    <span class="bar3"></span>
  </div>
  <ul class="menu">
    <li class="active"><a href="#section1">Section 1</a></li>
    <li><a href="#section2">Section 2</a></li>
    <li><a href="#section3">Section 3</a></li>
    <li><a href="#section4">Section 4</a></li>
    <li><a href="#section5">Section 5</a></li>
    <li><a href="#section6">Section 6</a></li>
  </ul>
</nav>
<section id="contents">
  <div id="section1">
    <h2>Section 1</h2>
  </div>
  <div id="section2">
    <h2>Section 2</h2>
  </div>
  <div id="section3">
    <h2>Section 3</h2>
  </div>
  <div id="section4">
    <h2>Section 4</h2>
  </div>
  <div id="section5">
    <h2>Section 5</h2>
  </div>
  <div id="section6">
    <h2>Section 6</h2>
  </div>
</section>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  font-family: "lato";
}
li {
  list-style: none;
}
a {
  text-decoration: none;
}
#nav {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.3);
}
#nav h1 {
  float: left;
  color: #fff;
  font-size: 40px;
  font-family: "Abel";
  padding: 5px 5px 5px 15px;
}
#nav ul {
  float: right;
  padding-right: 10px;
}
#nav ul li {
  display: inline;
}
#nav ul li a {
  display: inline-block;
  padding: 20px 15px;
  color: #fff;
  font-weight: bold;
  text-transform: capitalize;
  font-family: "Abel";
}
#nav ul li.active a {
  color: #000;
}
#nav .ham {
  display: none;
  position: absolute;
  top: 12px;
  right: 10px;
  width: 65px;
  height: 45px;
  cursor: pointer;
}
.ham span {
  display: block;
  background: #fff;
  width: 42px;
  height: 4px;
  border-radius: 3px;
  transition: margin 0.25s 0.25s, transform 0.25s;
}
.ham .bar1 {
  margin-bottom: 8px;
}
.ham .bar2 {
}
.ham .bar3 {
  margin-top: 8px;
}
.ham.active span {
  transition: margin 0.25s, transform 0.25s 0.25s;
}
.ham.active .bar1 {
  margin-top: 8px;
  margin-bottom: -4px;
  transform: rotate(45deg);
}
.ham.active .bar2 {
  transform: rotate(45deg);
}
.ham.active .bar3 {
  margin-top: -4px;
  transform: rotate(135deg);
}
#contents {
  text-align: center;
  color: #fff;
}
#contents > div {
  height: 100vh;
  line-height: 100vh;
}
#contents > div h2 {
  font-size: 6vw;
  font-weight: 100;
  text-transform: uppercase;
}
#contents > div h2 strong {
  font-weight: 700;
  font-style: italic;
}
#section1 {
  background: radial-gradient(
    ellipse farthest-corner at center top,
    #cbf49a,
    #1ea623
  );
}
#section2 {
  background: radial-gradient(
    ellipse farthest-corner at center top,
    #f39264 0%,
    #f2606f 100%
  );
}
#section3 {
  background: radial-gradient(
    ellipse farthest-corner at center top,
    #ffee75,
    #ff8930
  );
}
#section4 {
  background: radial-gradient(
    ellipse farthest-corner at center bottom,
    #6beace,
    #2e9aa4
  );
}
#section5 {
  background: radial-gradient(
    ellipse farthest-corner at center bottom,
    #69d2fb 0%,
    #20438e 100%
  );
}
#section6 {
  background: radial-gradient(
    ellipse farthest-corner at center top,
    #6cebcf 0%,
    #38a7aa 100%
  );
}
@media (max-width: 800px) {
  #nav .menu {
    display: none;
  }
  #nav .ham {
    display: block;
  }

  #nav h1 {
    width: 100%;
  }
  #nav .menu {
    float: none;
    text-align: center;
    padding-right: 0;
  }
  #nav .menu li {
    width: 100%;
    display: inline-block;
  }
  #nav .menu li.active {
    background-color: rgba(255, 255, 255, 0.3);
  }
}
.ham.active + .menu {
  display: block !important;
}

              
            
!

JS

              
                (function (window) {
  NodeList.prototype.findIndex = Array.prototype.findIndex;
  let Parallax = function () {
    this.init();
    return this;
  };

  Parallax.prototype = {
    nav_items: undefined,
    content_items: undefined,
    init: function () {
      let self = this;
      self.nav_items = document.querySelectorAll("#nav ul li");
      self.content_items = document.querySelectorAll("#contents > div");
      self.nav_items.forEach(self.setupNavClickEvent.bind(self));
      self.setupWindowScrollEvent();
      self.setupHamEvent();
    },
    setupNavClickEvent: function (item) {
      let self = this;
      item.addEventListener("click", function (evt) {
        evt.preventDefault();
        let target = evt.target;
        let index = self.nav_items.findIndex(
          (n) => n.firstChild.href == target.href
        );
        let section = self.content_items[index];
        let offset = section.offsetTop;
        window.scrollTo(0, offset);
      });
    },
    setupWindowScrollEvent: function () {
      let self = this;
      window.addEventListener("scroll", function (evt) {
        let wScroll = window.scrollY;
        self.content_items.forEach(function (n, index) {
          if (wScroll >= n.offsetTop) {
            self.nav_items.forEach((n) => n.classList.remove("active"));
            self.nav_items[index].classList.add("active");
          }
        });
      });
    },
    setupHamEvent: function () {
      let self = this;
      let ham = document.querySelector(".ham");
      ham.addEventListener("click", function (evt) {
        ham.classList.toggle("active");
      });
      window.addEventListener("resize", function () {
        let width = window.innerWidth;
        if (width > 830) {
          ham.classList.remove("active");
        }
      });
    }
  };

  new Parallax();
})(window);

              
            
!
999px

Console