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

              
                <p>scroll down</p>
<section class="section first">
  <div class="ball"></div>
</section>
<section class="section middle">
  <div class="content"></div>
</section>
<section class="section"></section>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  text-align: center;
}

p {
  margin-top: 1rem;
}

body {
  background-image: linear-gradient(
      rgba(255, 255, 255, 0.05) 2px,
      transparent 2px
    ),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 2px, transparent 2px),
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
  background-position: -2px -2px, -2px -2px, -1px -1px, -1px -1px;
}

.section {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.section.middle {
  height: 50vh;
}

.content {
  width: 100%;
  height: 200px;
  border: 2px dashed var(--color-surface-white);
  display: flex;
  justify-content: center;
  align-items: center;
}

.ball {
  width: 150px;
  height: 150px;
  border-radius: 9999px;
  background: var(--color-ui-text-gradient);
}

              
            
!

JS

              
                console.clear();
gsap.registerPlugin(ScrollTrigger, Flip);

let ball = document.querySelector(".ball"),
  parentSection = document.querySelector(".section.first"),
  content = document.querySelector(".content"),
  flipCtx;

const createTween = () => {
  flipCtx && flipCtx.revert();

  flipCtx = gsap.context(() => {
    let state = Flip.getState(ball); // grab the state so we can record where the ball is
    content.appendChild(ball); // reparent
    Flip.fit(ball, state); // apply transforms to fit the ball visually where it was previously when we captured the state
    console.log(state);

    const tl = gsap
      .timeline({
        scrollTrigger: {
          trigger: parentSection,
          start: "bottom 85%",
          end: "bottom 25%",
          scrub: 1,
          immediateRender: false,
          markers: true
        }
      })
      .to(ball, { x: "40vw", ease: "none" })
      .to(ball, { y: 0, ease: "none" })
      .to(ball, { x: 0, ease: "none" });
    return () => {
      console.log();
      // when the context reverts, return the ball to the original parentSection and clear the inline styles
      parentSection.appendChild(ball);
      gsap.set(ball, { clearProps: "all" });
    };
  });
};

createTween();

window.addEventListener("resize", createTween);

              
            
!
999px

Console