Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                  <div class="parallax-container">
    <div class="parallax-layer layer-0" data-parallax-speed="0.05" data-max-scroll="465"></div>
    <div class="parallax-layer layer-1" data-parallax-speed="0.1" data-max-scroll="465"></div>
    <div class="parallax-layer layer-2" data-parallax-speed="0.3" data-max-scroll="465"></div>
    <div class="parallax-layer layer-3" data-parallax-speed="0.5" data-max-scroll="465"></div>
    <div class="parallax-layer layer-4" data-parallax-speed="0.7" data-max-scroll="465"></div>
    <div class="parallax-layer layer-5" data-parallax-speed="0.9" data-max-scroll="465"></div>
  </div>

  <div class="content">
    <div id="a8" class=""><h1>This is parallax.</h1></div>
  </div>
              
            
!

CSS

              
                body {
  background: #415a6c;
  margin: 0;
  font-family: 'Oswald';
}
.parallax-container {
  position: fixed;
  overflow: visible;
  width: 100%;
  height: 850px;
}
.parallax-layer {
  width: 100%;
  height: 500px;
  position: fixed;
  left: 0;
  top: 0;
  background-position: bottom center;
  background-repeat: repeat-x;
  background-size: 960px 253px;
}
  .layer-0 {
    top: 0;
    z-index: 5;
    background: #dbf0ff url('https://i.imgur.com/4hwp8up.png') no-repeat top 40px center;
    background-size: 120px 138.5px;
  }
  .layer-1 {
    top: -100px;
    z-index: 5;
    background-image: url('https://i.imgur.com/Ra2bzmb.png');
  }
  .layer-2 {
    top: -50px;
    z-index: 10;
    background-image: url('https://i.imgur.com/jSOo9SK.png');
  }
  .layer-3 {
    top: -10px;
    z-index: 15;
    background-image: url('https://i.imgur.com/DOZRBDj.png');
  }
  .layer-4 {
    top: 65px;
    z-index: 20;
    background-image: url('https://i.imgur.com/JbSR9JY.png');
  }
  .layer-5 {
    top: 150px;
    z-index: 25;
    background-image: url('https://i.imgur.com/Ti2mNxd.png');
  }

  
.content {
  position: absolute;
  top: 600px;
  background: #415a6c;
  width: 100%;
  min-height: 1500px;
}
  .content h1 {
    color: #fff;
    font-size: 2em;
    text-transform: uppercase;
    text-align: center;
  }

.stick {
    position: fixed;
    top: 0;
}
              
            
!

JS

              
                var ParallaxManager, ParallaxPart;

ParallaxPart = (function() {
  function ParallaxPart(el) {
    this.el = el;
    this.speed = parseFloat(this.el.getAttribute('data-parallax-speed'));
    this.maxScroll = parseInt(this.el.getAttribute('data-max-scroll'));
  }

  ParallaxPart.prototype.update = function(scrollY) {
    if (scrollY > this.maxScroll) { return; }
    var offset = -(scrollY * this.speed);
    this.setYTransform(offset);
  };

  ParallaxPart.prototype.setYTransform = function(val) {
    this.el.style.webkitTransform = "translate3d(0, " + val + "px, 0)";
    this.el.style.MozTransform    = "translate3d(0, " + val + "px, 0)";
    this.el.style.OTransform      = "translate3d(0, " + val + "px, 0)";
    this.el.style.transform       = "translate3d(0, " + val + "px, 0)";
    this.el.style.msTransform     = "translateY(" + val + "px)";
  };

  return ParallaxPart;

})();

ParallaxManager = (function() {
  ParallaxManager.prototype.parts = [];

  function ParallaxManager(elements) {
    if (typeof elements === 'array' && elements.length) {
      this.elements = elements;
    }
    if (typeof elements === 'object' && elements.item) {
      this.elements = Array.prototype.slice.call(elements);
    } else if (typeof elements === 'string') {
      this.elements = document.querySelectorAll(elements);
      if (this.elements.length === 0) {
        throw new Error("Parallax: No elements found");
      }
      this.elements = Array.prototype.slice.call(this.elements);
    } else {
      throw new Error("Parallax: Element variable is not a querySelector string, Array, or NodeList");
    }
    for (var i in this.elements) {
      this.parts.push(new ParallaxPart(this.elements[i]));
    }
    window.addEventListener("scroll", this.onScroll.bind(this));
  }

  ParallaxManager.prototype.onScroll = function() {
    window.requestAnimationFrame(this.scrollHandler.bind(this));
  };

  ParallaxManager.prototype.scrollHandler = function() {
    var scrollY = Math.max(window.pageYOffset, 0);
    for (var i in this.parts) { this.parts[i].update(scrollY); }
  };

  return ParallaxManager;

})();

new ParallaxManager('.parallax-layer');
//
var top = document.getElementById('a8').offsetTop;

window.onscroll = function() {
    var y = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
    if (y >= top) {
        a8.className = 'stick';
    }
    else {
        a8.className = '';
    }
};
              
            
!
999px

Console