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>
  <div id="intro">
    <div id="banner" style="background-image:url('https://i.imgur.com/S3qLyik.jpg');">
      <p>Page loads with a 70% height banner, and a lower header portion at 30% height, with the h1 vertically aligned in the middle.</p>
      <p>As the page scrolls, the banner should be position fixed (pinned) and reduce to 50% height, at which point it unpins.</p>
    </div>
    <div id="main-title">
      <h1 id="header_title" class="cinzel light">30% HEIGHT HEADER, VERTICALLY ALIGNED IN THE MIDDLE. SCROLLING UP ABOVE THE BANNER, AND FADING TO 0 OPACITY.</h1>
      <div id="reveal">
        <img id="piano" src="https://i.imgur.com/4ciexs6.png" />
        <h1 id="subheader_title" class="cinzel">SUB-HEADER</h1>
        <p id="intro" class="gothic">Once the banner has reduced to 50% window height, the page should continue scrolling normally.</p>
      </div>
    </div>
  </div>
</main>
              
            
!

CSS

              
                html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: arial;
  background-size: cover;
  background-position: center center;
  background-attachment: fixed;
}

.cinzel.light {
  font-weight: 400;
}

.gothic {
  font-family: "alternate-gothic-no-2-d";
}

h1 {
  font-size: 30px;
  margin: 0;
}

main {
  text-align: center;
  color: #000;
}

#banner {
  position: relative;
  display: block;
  float: left;
  width: 100%;
  background-position: center center;
  background-size: contain;
  z-index: 1;
}

#main-title {
  position: relative;
  display: block;
  float: left;
  width: 100%;
  z-index: 1;
}
              
            
!

JS

              
                $(document).ready(function() {

  set_heights();

  overall_h = $('#main-title').height();
  console.log(overall_h);

  var mainWrapper = document.getElementsByTagName('main')[0],
    banner = document.getElementById('banner'),

    // set the duration in pixels
    duration = wh + $('#main-title').height(),

    // define the main controller for ScrollMagic
    // (we can have multiple controllers if needed)
    controller = new ScrollMagic.Controller({
      loglevel: 0,
      globalSceneOptions: {
        // set trigger hook to top of viewport
        triggerHook: 0
      }
    });

  // start a new ScrollMagic scene by calling the
  // provided method from the ScrollMagic Class
  var bannerScene = new ScrollMagic.Scene({
    triggerElement: mainWrapper,
    duration: lower_height
  })

  // start our tween/animation
  bannerScene.setTween(new TimelineMax().add([
    TweenMax.to(banner, 1, {
      height: wh/2
    }),
    TweenMax.to('h1#header_title', 1, {
      opacity: 1,
      y: -100
    }),
  ]))

  // set hero block fixed for duration of wrapper
  bannerScene.setPin('#banner', {
    pushFollowers: false
  })

  // add helpful indicators to help with setting up animations right
  bannerScene.addIndicators()

  // finally, we add the animation to the
  // main controller we defined in the beginning
  bannerScene.addTo(controller);

  bannerScene.on("end", function(event) {
    console.log("End banner scene");
  });

  // start a new ScrollMagic scene by calling the
  // provided method from the ScrollMagic Class
  var revealScene = new ScrollMagic.Scene({
    triggerElement: mainWrapper,
    duration: upper_height
  })

  // start our tween/animation
  revealScene.setTween(new TimelineMax().add([
    TweenMax.to('#reveal', 1, {
      opacity: 1,
      y: -100
    }),
  ]))

  // add helpful indicators to help with setting up animations right
  revealScene.addIndicators()

  // finally, we add the animation to the
  // main controller we defined in the beginning
  revealScene.addTo(controller);

  revealScene.on("end", function(event) {
    console.log("End reveal scene");
  });

});

$(window).resize(function() {
  set_heights();
});

function set_heights() {
  wh = window.innerHeight;
  upper_height = 70 * wh / 100;
  lower_height = 30 * wh / 100;
  h1_pad = lower_height / 2 - $('h1#header_title').height() / 2;
  $('h1#header_title').css('padding-top', h1_pad + 'px');
  $('h1#header_title').css('padding-bottom', h1_pad + 'px');
  $('#banner').css('height', upper_height + 'px');
}
              
            
!
999px

Console