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

              
                <main class="content js-content">
  
  <section class="block section-landing">
    <figure class="item-parallax-media">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/46992/luca-bravo-189272.jpg" alt="" />
    </figure>
    <div class="item-parallax-content flex-container">
      <div class="landing-content centered-content">
        <h1 class="head-large">We love Things</h1>
      </div>
    </div>
  </section>
  
  <section class="block section-intro">
    <div class="item-parallax-content flex-container">
      <div class="centered-content">
        <h2 class="head-small head-centered">Visibility</h2>
        <p class="copy copy-white">
        One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections.
        </p>
        <p class="copy copy-white">
  The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me?" he thought.
        </p>
      </div>
    </div>
  </section>
  
  <section class="block section-part">
    <figure class="item-parallax-media">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/46992/roberta-sorge-138285.jpg" alt="" />
    </figure>
    <div class="item-parallax-content flex-container">
      <div class="centered-content">
        <h1 class="head-large head-centered">Garden <br/>of Eden</h1>
        <p class="copy copy-white">
          One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.
        </p>
      </div>
    </div>
  </section>
  
  <section class="block">
    <div class="item-parallax-content flex-container img-grid">
      <figure class="img-gridItem type-right">
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/46992/andrew-branch-139678.jpg" alt="" />
        <figcaption class="img-caption">
          <h2 class="head-small">Free Soul</h2>
          <p class="copy copy-white">
            Apparently we had reached a great height in the atmosphere, for the sky was a dead black, and the stars had ceased to twinkle.
          </p>
        </figcaption>
      </figure>
      <figure class="img-gridItem type-left">
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/46992/peter-hershey-112799.jpg" alt="" />
        <figcaption class="img-caption">
          <h2 class="head-small">Free Mind</h2>
          <p class="copy copy-white">
            A peep at some distant orb has power to raise and purify our thoughts like a strain of sacred music, or a noble picture, or a passage from the grander poets.
          </p>
        </figcaption>
      </figure>
    </div>
  </section>
  
  <section class="block section-end">
    <figure class="item-parallax-media">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/46992/noah-silliman-141979.jpg" alt="" />
    </figure>
    <div class="item-parallax-content flex-container">
      <div class="landing-content centered-content">
        <h1 class="head-large">Back to Basic</h1>
      </div>
    </div>
  </section>
  
  <section class="custom-properties-ftw">
    <h3 class="head-small head-centered">Yeah Custom Properties</h3>
  </section>
</main>
              
            
!

CSS

              
                *, *:before, *:after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.content {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  clip-path: border-box;
  transform: translateZ(0);
}

.block {
  position: relative;
  height: 100vh;
}

[class*='item-parallax'] {
  position: absolute;
  width: 100%;
  height: 100%;
  transition: transform 0.3s ease-out;
  will-change: transform; // prevents paint flashing
}

.item-parallax-media {
  z-index: 1;
  
  img {
    will-change: transform; // prevents paint flashing
  }
}
.item-parallax-content {
  z-index: 2;
}


$boxes: 5;
@for $i from 1 through $boxes {
  .block:nth-child( #{$i} ) .item-parallax-content {
    transform: translateY( calc( var(--yBlock-#{$i}) * 0.5px ) );
  }
  .block:nth-child( #{$i} ) .item-parallax-media img {
    transform: translateY( calc( var(--yBlock-#{$i}) * 0.1px ) );
  }
}


// --------------- layout

$dark: #00171f;
$light: white;

@mixin font($type:regular) {
  @if $type == head {
    font-family: 'Inknut Antiqua', serif;
  }
  @if $type == regular {
    font-family: 'Roboto', sans-serif;
  }
  @if $type == condensed {
    font-family: 'Roboto Condensed', sans-serif;
  }
}

@mixin font-smoothing($value: on) {
  @if $value == on {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  @else {
    -webkit-font-smoothing: subpixel-antialiased;
    -moz-osx-font-smoothing: auto;
  }
}

html {
  background-color: $dark;
}

.flex-container {
  display: flex;
}
.centered-content {
  margin: auto;
}

.head-large {
  margin-bottom: 5vw;
  font-size: 10vw;
  line-height: 1.2em;
  @include font(head);
  color: $light;
}
.head-small {
  margin-bottom: 1.5rem;
  font-size: 1.2rem;
  line-height: 1.2em;
  @include font(condensed);
  color: $light;
  text-transform: uppercase;
  letter-spacing: 0.5em;
  @include font-smoothing(on);
}
.head-centered {
  text-align: center;
}



.copy {
  display: block;
  max-width: 500px;
  margin-right: auto;
  margin-bottom: 1.5rem;
  margin-left: auto;
  padding-right: 1.5rem;
  padding-left: 1.5rem;
  @include font(regular);
  font-size: 1rem;
  line-height: 1.8em;
  text-align: center;
}
.copy-white {
  color: $light;
  @include font-smoothing(on);
}







.item-parallax-media {
  overflow: hidden;
  
  img {
    position: absolute;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    object-fit: cover;
  }
}

// ------------ landing
.section-landing:before {
  content: '';
  position: absolute;
  top: 50%;
  left: 24%;
  width: 10px;
  height: 80%;
  background-color: white;
  z-index: 3;
  transform: translateY(-13vw);
}

.section-landing .item-parallax-media {
  opacity: calc( 1 - (var(--y) * 0.0009) );
}

.landing-content {
  padding-left: 30%;
}

// ---------------- intro
.section-intro:before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 80%;
  background-color: mix($light, $dark, 5%);
  transform: 
    translateX(-50%) 
    translateY(-50%) 
    rotate( calc( (var(--y) * 0.1deg) ) );
  will-change: transform;
  backface-visibility: visible;
}


// ------------------ image grid
.img-grid {
  flex-direction: column;
  justify-content: space-around;
}

.img-gridItem {
  position: relative;
  width: 100%;
  max-width: 800px;
  margin-right: auto;
  margin-left: auto;
  
  img {
    display: block;
    width: 50%;
    height: 40vh;
    object-fit: cover;
    will-change: transform;
    backface-visibility: visible;
  }
  
  &.type-left img {
    margin-right: auto;  
  }
  &.type-right img {
    margin-left: auto;  
  }
}

.img-gridItem {
  &:nth-child(1) img {
    transform: translateX( calc( var(--yBlock-4) * -0.03% ) );
  }
  &:nth-child(2) img {
    transform: translateX( calc( var(--yBlock-4) * 0.03% ) );
  }
}

.img-caption {
  position: absolute;
  top: 50%;
  width: 50%;
  transform: translateY(-50%);
  
  * {
      text-align: left;
      padding-right: 1.5rem;
      padding-left: 1.5rem;
    }
  
  .type-left & {
    right: 0;
  }
  .type-right & {
    left: 0;
  }
}


// ---------------- end
.section-end:before {
  content: '';
  position: absolute;
  bottom: 50%;
  left: 24%;
  width: 10px;
  height: 80%;
  background-color: white;
  z-index: 3;
  transform: translateY(8vw);
}


// -------------- kind of a footer
.custom-properties-ftw {
  padding: 2.5rem 1.5rem;
  
  .head-small {
    margin-bottom: 0;
  }
}
              
            
!

JS

              
                const body = document.body;
const content = document.querySelector('.js-content');
const blocks = document.querySelectorAll('.block');

const updateOffset = () => {
  requestAnimationFrame(updateOffset);
  body.style.setProperty('--y', content.scrollTop);
  updateProps();
}

const updateProps = () => {  
  let i = -1;
  for(let block of blocks) {
    i += 1;
    let top = blocks[i].getBoundingClientRect().top;
    if(top < window.innerHeight*1.3 && top > window.innerHeight*-1.3) {
      body.style.setProperty(`--yBlock-${i+1}`, top);
    } else {
      body.style.setProperty(`--yBlock-${i+1}`, 0); 
    }
  }
}

updateProps();
updateOffset();
              
            
!
999px

Console