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="target">
	<img src="https://www.voicesofyouth.org/sites/voy/files/images/2020-08/finding-sunshine.jpg" />
</div>
<section>
	<h1>SECTION 01</h1>
</section>
<section>
	<h1>SECTION 02</h1>
</section>
<section>
	<h1>SECTION 03</h1>
</section>
<section>
	<h1>SECTION 04</h1>
</section>
              
            
!

CSS

              
                body{
  margin:0;
  width:100%;
  background-color:grey;
  font-family:sans-serif;
  text-align:center;
  overscroll-behavior: none;
}
section{
  position:relative;
  height:100vh;
  border-bottom:1px solid #636363;
  width: 50%;
}
h1{
  position:absolute;
  top:50px;
  font-size:50px;
  line-height: 1;
  font-family:sans-serif;
  color: #fff;
  margin: 0 0 0 20px;
}
#target {
  width: 40%;
  position: fixed;
  right: 0;
  top: 0;
  background: #333;
  height: 100vh;
  overflow: hidden;
}
#target img {
  width: 100%;
}
              
            
!

JS

              
                // This effect lets you zoom in on a particular spot on the target - you define the scale and the origin as an Array of x/y normalized values.
// Like {scale: 3, origin: [0.25, 0.8]} will zoom in on the spot that's 25% from the left, and 80% from the top of the element/image.
// It will return an animation that controls the xPercent, yPercent, and scale (as well as any other values you pass in, like a normal tween)
// It won't let the edges collapse toward the center. It's best to put the element into a container that has overflow: hidden.
gsap.registerEffect({
  name: "zoom",
  effect: (targets, config) => {
    const vars = {transformOrigin: "0px 0px", ...config},
          { scale, origin } = config,
          clamp = gsap.utils.clamp(-100 * (scale - 1), 0);
    delete vars.origin;
    vars.xPercent = clamp((0.5 - origin[0] * scale) * 100);
    vars.yPercent = clamp((0.5 - origin[1] * scale) * 100);
    vars.overwrite = "auto";
    return gsap.to(targets, vars);
  },
  extendTimeline: true,
  defaults: {origin: [0.5, 0.5], scale: 2}
});

// for each section, we define the zoom data here
const zoomData = [
  {scale: 1, origin: [0.5, 0.5]},
  {scale: 3, origin: [0.25, 1]},
  {scale: 1, origin: [0.5, 0.5]},
  {scale: 2, origin: [0.8, 0.4]}
];

// now loop through each section and create the ScrollTrigger accordingly.
// when that section enters from either direction, it'll fire off the zoom animation.
gsap.utils.toArray("section").forEach((section, index) => {
  const zoom = zoomData[index];
  ScrollTrigger.create({
    trigger: section,
    start: "top 85%",
    end: "+=95%",
    onToggle(self) {
      if (self.isActive) { // if it enters forward or backward
        gsap.effects.zoom("#target img", {
          scale: zoom.scale,
          origin: zoom.origin,
          duration: 1,
          ease: "power1.inOut"
        });
      }
    }
  });
});
              
            
!
999px

Console