Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Learning

Zoom out then scroll effect?

Recommended Posts

Hi guys,

 

I'm wondering how this effect is achieved?
https://pitch.com/
What happens is that the hero image slowly zooms out as the user scrolls,

revealing that is is a screen within a device,

then the device with the hero image scrolls as per normal on the page.

I'm thinking that it can probably be achieved with the new scroll trigger plugin,

but it's anchored and zoomed, plus the ending when it scrolls normally felt a little confusing as to how it works.
Not to mention getting the size right to frame the device just outside the screen based on screen size.

Link to comment
Share on other sites

Hey Learning. 

 

Using ScrollTrigger this effect is easy! Just scale the element using a tween and apply a ScrollTrigger with pinning:

See the Pen LYGbJEP by GreenSock (@GreenSock) on CodePen

 

We have a more complex demo of the same sort of effect as well:

See the Pen wvKwZXG by GreenSock (@GreenSock) on CodePen

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

I am trying to implement the same effect in React but I am very confused. How can I implement the same effect in useEffect?

Link to comment
Share on other sites

Hi there - have you seen our React guide?
 

  • Like 1
Link to comment
Share on other sites

2 hours ago, Cassie said:

Hi there - have you seen our React guide?
 

Hey thanks for the answer :) I am a newbie using gsap and I am trying to get more familiar using it with react ecosystem. I started reading docs and I try to implement different solutions as well as watching other tutorials.

 

I tried to use that code in such a code block in React:

import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import { useRef, useEffect } from 'react';
import './Animation.css';

gsap.registerPlugin(ScrollTrigger);
gsap.set('.gridBlock', {
  backgroundImage: (i) =>
    `url(https://picsum.photos/${500}/${500}?random=${i})`,
});
const Animation = () => {
  const imageRef = useRef(null);
  useEffect(() => {
    const el = imageRef.current;
    gsap
      .timeline({
        scrollTrigger: {
          trigger: document.querySelector('.grid-container'),
          start: 'top top',
          end: () => 400 * 4,
          scrub: true,
          pin: document.querySelector('.grid'),
          anticipatePin: 1,
        },
      })
      .set('.gridBlock:not(.centerBlock)', { autoAlpha: 0 })
      .to(
        '.gridBlock:not(.centerBlock)',
        { duration: 0.1, autoAlpha: 1 },
        0.001
      )
      .from('.gridLayer', {
        scale: 3.3333,
        ease: 'none',
      });
  }, []);
  return (
    <div className="grid-container">
      <div className="grid">
        <div className="gridLayer">
          <div className="gridBlock"></div>
        </div>
        <div className="gridLayer">
          <div className="gridBlock"></div>
        </div>
        <div className="gridLayer">
          <div className="gridBlock"></div>
        </div>
        <div className="gridLayer centerPiece">
          <div className="gridBlock centerBlock"></div>
        </div>
        <div className="gridLayer">
          <div className="gridBlock"></div>
        </div>
        <div className="gridLayer">
          <div className="gridBlock"></div>
        </div>
        <div className="gridLayer">
          <div className="gridBlock"></div>
        </div>
        <div className="gridLayer">
          <div className="gridBlock"></div>
        </div>
        <div className="gridLayer">
          <div className="gridBlock"></div>
        </div>
      </div>
    </div>
  );
};

export default Animation;

yet for now I couldn't figure out why it's not working properly. I will appreciate every single help :) 

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×