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

              
                <section id="main-section">
  <img src="https://placekitten.com/1920/1920" alt="a cute hidden cat" id="bg-image" />
</section>

<section id="next-section">
  Meow!
</section>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
}

#main-section {
  background: #333;
  position: relative;
  width: 100%;
  height: 100vh;
}

#bg-image {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

#bg-image {
  object-fit: cover;
  clip-path: circle(var(--radius) at var(--x) var(--y));
  --radius: 0px;
  --x: 0px;
  --y: 0px;
}

#next-section {
  background-color: #ff6289;
  height: 50vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-style: italic;
}

              
            
!

JS

              
                const mainSection = document.getElementById("main-section");
const bgImage = document.getElementById("bg-image");

const animationTimingProps = {
  duration: 1,
  ease: Expo.easeOut
};

const setRadius = gsap.quickTo(bgImage, "--radius", {
  ...animationTimingProps
});

const setX = gsap.quickTo(bgImage, "--x", {
  ...animationTimingProps
});

const setY = gsap.quickTo(bgImage, "--y", {
  ...animationTimingProps
});

const scrollThreshold = 10;
let isScrolling = false;

// Part 1:
mainSection.addEventListener("mousemove", (e) => {
  if (isScrolling) return false;
  const { pageY: y, pageX: x } = e;
  setRadius(100);
  setX(x);
  setY(y);
});

document.addEventListener("scroll", () => {
  isScrolling = window.scrollY > scrollThreshold;
});

// Part 2:
const {
  width: sectionWidth,
  height: sectionHeight
} = mainSection.getBoundingClientRect();

// Using scrub:
const timeline = gsap.timeline({
  scrollTrigger: {
    trigger: mainSection,
    scrub: 1,
    start: `bottom+=${scrollThreshold} bottom`,
    refreshPriority: 10,
    end: `${window.innerHeight * 3}`,
    toggleActions: "play none reverse reset",
    pin: true
  }
});

timeline.to(bgImage, {
  "--radius": `${sectionWidth * 0.8}px`
});

// Without using scrub. The idea is to make the circle radius attached to the scrub animation, and also move the clip path smoothly to the center when user scrolls down

gsap.to(bgImage, {
  "--x": `${sectionWidth / 2}px`,
  "--y": `${sectionHeight / 2}px`,
  duration: 2,
  scrollTrigger: {
    trigger: mainSection,
    start: `bottom+=${scrollThreshold} bottom`,
    toggleActions: "play none reverse reverse"
  }
});

              
            
!
999px

Console