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 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

              
                <div id="banner">
  <div class="image-clip">
    <div class="hero-image"></div>
  </div>
</div>
              
            
!

CSS

              
                #banner {
  width: 300px;
  height: 250px;
  border: 1px solid red;
  visibility: hidden;
}

.image-clip {
  position: absolute;
  width: 300px;
  height: 190px;
  overflow: hidden;
  clip: rect(0 300px 160px 0);
}

.hero-image {
  position: absolute;
  background: url('https://placekitten.com/300/225') no-repeat;
  background-color: blue;
  width: 300px;
  height: 250px;
}
              
            
!

JS

              
                var masterTl,
  heroImage = document.getElementsByClassName('hero-image'),
  imageClip = document.getElementsByClassName('image-clip');

function frame1() {
  var tl = new TimelineLite();

  tl
    .add("start")
    .fromTo(imageClip, 0.1, {
      clip: "rect(0 300px 160px 0)"
    }, {
      clip: "rect(0 300px 160px 0)"
    })
    .from(imageClip, 1, {
      y: "-=200",
      autoAlpha: 0,
      ease: Strong.easeOut
    }, "start")
    .to(imageClip, 0.6, {
      autoAlpha: 0,
      ease: Strong.easeOut
    }, "+=2")

  return tl;
}

function frame2() {
  var tl = new TimelineLite();

  tl
    .set(heroImage, {
      y: -35
    }, 0.1) /* how come this y-position is applied at the beginning of the animation? Comment it out to see the difference. */
    .fromTo(imageClip, 0.1, {
      clip: "rect(0 300px 190px 0)"
    }, {
      clip: "rect(0 300px 190px 0)"
    })
    /* I was having the same issue with the clip being applied immediately, at the beginning of the animation. Using fromTo() seems to have helped fix that. */
    .fromTo(imageClip, 2, {
      autoAlpha: 0,
      y: -200
    }, {
      autoAlpha: 1,
      y: 0,
      ease: Strong.easeOut
    });

  return tl;
}

function createMasterTimeline() {
  masterTl = new TimelineLite();
  masterTl
    .set(banner, {
      autoAlpha: 1
    })
    .add(frame1(), 0.3)
    .add(frame2())
}

createMasterTimeline();
              
            
!
999px

Console