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 class="right-side">
  <div class="photo"></div>
</div>
<section>
	<h1>ScrollTrigger Zoom by Section</h1>
</section>
<section>
	<h1>Section 2</h1>
</section>
<section>
	<h1>Section 3</h1>
</section>
<section>
	<h1>Section 4</h1>
</section>
              
            
!

CSS

              
                body {
  margin: 0;
  width: 100%;
  background-color: grey;
  font-family: sans-serif;
  overscroll-behavior: none;
}
section {
  position: relative;
  height: 100vh;
  border-bottom: 1px solid #636363;
  width: 58%;
}
h1 {
  position: absolute;
  top: 30px;
  font-size: 36px;
  line-height: 1;
  font-family: sans-serif;
  color: #fff;
  margin: 0 0 0 20px;
}
.right-side {
  width: 40%;
  position: fixed;
  right: 0;
  top: 0;
  background: #333;
  height: 100vh;
  overflow: hidden;
}
.photo {
  width: 100%;
  height: 100%;
  background-image: url(https://www.voicesofyouth.org/sites/voy/files/images/2020-08/finding-sunshine.jpg);
  background-size: cover;
  background-position: center;
}
              
            
!

JS

              
                /* 
This GSAP effect lets you zoom in on a particular spot of 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]} would 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.

Example: 

gsap.effects.zoom(".photo", {
  scale: 3,
  origin: [0.25, 0.8],
  duration: 1,
  ease: "power1.inOut"
});
 */
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.6, 1]},
    {scale: 1, origin: [0.5, 0.5]},
    {scale: 2, origin: [0.8, 0.4]}
  ],
  // now create the timeline that we'll scrub
  tl = gsap.timeline({
    scrollTrigger: {
      start: 0, // start from the top
      end: "+=" + ((zoomData.length - 1) * 100) + "%", // each section is 100% of the viewport height
      scrub: 0.5 // take 0.5 to catch up to scroll position
    }
  });

// set the starting state
gsap.effects.zoom(".photo", {scale: zoomData[0].scale, origin: zoomData[0].origin, duration: 0});

// now loop through subsequent sections and create the ScrollTrigger accordingly.
zoomData.slice(1).forEach(data => {
  tl.zoom(".photo", {
    scale: data.scale,
    origin: data.origin,
    ease: "power1.inOut"
  });
});
              
            
!
999px

Console