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

              
                <div class="wrapper">
  <nav>
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
        <a class="navbar-brand" href="#"><i class="fa fa-codepen"></i></a>
        <p class="navbar-text navbar-right">Made with <strong>ES6</strong></p>
      </div>
    </div>
  </nav>
  <section class="hero vertical-center">
    <div class="container text-center">
      <h1>Easy Rainbow Parallax</h1>
    </div>
    <div class="optional-rainbow"></div>
  </section>
  <section class="content">
    <div class="container">
      <article>
        <div class="col-sm-6 article-left">
          <img src="https://dl.dropbox.com/s/zugi03ayjbjc7or/coffeePour_sm.jpg?dl=1" alt="mmmm" class="article-image" style="max-width:100%;">
        </div>
        <div class="col-sm-6 article-right">
          <h2>EASY-PEASY</h2>
          <p>It's just a colored pseudo-element. ES6 Parallax scrolling/zooming just for fun.</p>
          <p>For added fun, toggle the version with increasing rainbow opacity!</p>
          <div class="control row">
            <div class="col-xs-8">Rainbopacity: </div>
            <div class="col-xs-3">
              <div class="selectable" class="off"></div>
            </div>
          </div>
        </div>
      </article>
    </div>
  </section>
</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Work+Sans:400,300,200,700);

html,body{
  display:block;
  width:100%;
  height:100%;
}
h1, h2, p {
  font-family:"Work Sans", serif;
}

.wrapper{ display:block; height:auto; position:relative; padding-bottom:3em;}

//THE IMPORTANT BIT

.hero{
  position:relative;
  height:100%;
  width:100%;
  background:url(https://dl.dropbox.com/s/9u786zwyehzuvam/cliffSide_mini.jpg?dl=1) no-repeat 50% 50% fixed;
  background-size:200%;
  overflow:hidden;
  
  h1{
    position:relative;
    z-index:50;
    color:white;
    font-size:80px;
    font-weight:200;
  }
  
  &.fadeout{
    .optional-rainbow{
      display:block;
    }
    &:before{
    display:none;
    }
  }
  
  &:before{
    display:block;
    position:absolute;
    height:100%;
    width:100%;
    z-index:5;
    content:"";
    background:-webkit-linear-gradient(#30f89c, #352ce6, #fc5e9d); 
    background: -moz-linear-gradient(left, #30f89c, #352ce6, #fc5e9d); 
    background:linear-gradient(#30f89c, #352ce6, #fc5e9d); 
    opacity:0.4;
  }
  
  &:after{
    display:block;
    position:absolute;
    bottom:0;
    left:0;
    content:"";
    width:100%;
    height:6px; 
    background: -webkit-linear-gradient(left, #30f89c, #352ce6, #fc5e9d); 
    background: -moz-linear-gradient(left, #30f89c, #352ce6, #fc5e9d); 
    background: linear-gradient(left, #30f89c, #352ce6, #fc5e9d);
    
  }
  
  .optional-rainbow{
    display:none;
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:100%;
    background: -webkit-linear-gradient(#30f89c, #352ce6, #fc5e9d); 
    background: -moz-linear-gradient(#30f89c, #352ce6, #fc5e9d); 
    background: linear-gradient(#30f89c, #352ce6, #fc5e9d);
    opacity:0.4;
    z-index:4;
  }
  
}


//SUPERFLUOUS STYLEY STUFF

nav {
  position:absolute;
  top:0;
  z-index:20;
  width:100%;
  color:white;
  
  >.container{
    position:relative;
  }
  
  .navbar-brand{
    color:white;
    font-size:26px;
  }
  .navbar-right{
    margin-right:1em;
    position:absolute;
    right:0;
  }
  
  > div{
    border-bottom:1px solid rgba(255,255,255,0.4);
  }
}

article{
  padding:3em 0;
  color:#545454;
  font-size:18px;
  
  .article-right{
    max-width:400px;
    margin:0 auto;
  }
  
  @media(max-width:767px){
    text-align:center;
    img{
      margin-bottom:2em;
    }
  }
   
  p{
    margin:2em 0;
  }
  
  h2{
    font-size:54px;
    font-weight:200;
    margin-top:0;
    text-transform:uppercase;
  }
  
  img{
    border:3px solid #e6e6e6;
  }
}

.control{
  width:100%;
  padding:0.5em 1em;
  background:#e6e6e6;
  border-radius:10px;
}

//control
.selectable{
  display:block;
  position:relative;
  width:40px;
  height:20px;
  background:rgba(255,44,44,0.6);
  border-radius:10px;
  box-shadow:inset 0 1px 2px rgba(0,0,0,0.2);
  transition:all .2s linear;
  
  &:before{
    display:block;
    position:absolute;
    content:"";
    width:20px;
    height:20px;
    border-radius:50%;
    background:white;
    box-shadow:0 2px 1px rgba(0,0,0,0.2);
    top:0;
    left:0;
    transition:all .2s linear;
  }
  
  &.on {
    background:rgba(44,255,44,0.5);
    
    &:before{
      left:calc(100% - 20px);
    }
  }
}

.vertical-center{
	min-height: 100%;  /* Fallback for browsers do NOT support vh unit */
  min-height: 100vh; /* These two lines are counted as one :-)       */

  display: flex;
  align-items: center;
}
              
            
!

JS

              
                window.onload=()=>{
  const ph = new ParallaxHero('.hero')
}

class ParallaxHero{
  constructor(q){
    this.element = q;
    this.bindScroll();
    this.sampleScroll();
  }
  bindScroll(){
    $(window).on('scroll', ()=>{
      const scrolled = $(window).scrollTop();
      //Move & fade the H1 on scroll.
      $(`${this.element} h1`).css({
        'top':`${scrolled * 0.7}px`,
        'opacity':`${1-(scrolled/$(this.element).outerHeight())*1.8}` 
      });
      //Move & zoom the hero background image
      $(this.element).css({
        'background-position':`50% calc(50% + ${scrolled * 0.2}px)`,
        'background-size': `${200 + (scrolled*50/$(this.element).outerHeight())}%`
      });
      //Fade the extra rainbow div just in case it's visible
      $(`${this.element} .optional-rainbow`).css('opacity', `${0.4 + (scrolled/$(this.element).outerHeight())}`);
    });  
    //added control to toggle the extra rainbow div, just for s&g
    $('.selectable').on('click', (e)=>{
      $('.selectable').toggleClass('on');
      $('.hero').toggleClass('fadeout');
    });
  }
  sampleScroll(){
    //move it so that it shows in portfolio
    setTimeout(function(){$.scrollTo(500, 2000)}, 500)
  }
  
}
              
            
!
999px

Console