Jump to content
Search Community

Left text scrolling right image pin

Iischeese test
Moderator Tag

Recommended Posts

I am trying to create a image animation pinning effect, it's hard to explain but heres a working demo deveb.co like this:

 

 

 

 

 

 

 

 

image.thumb.png.9a3db0616bf175d23272633f5f4de5f2.png

 

I'm using next js 14.1.2 and the scrolling effect on the images dosn't work. Any ideas?

 

 

 

function ScrollingSection() {

 

  const details = gsap.utils.toArray("#details:not(:first-child)")
  const photos = gsap.utils.toArray("#photo:not(:first-child)")

 

  let allPhotos = gsap.utils.toArray('#photos')

 

  const trigger = useRef()
  const pin = useRef()

 

  useGSAP( () => {
    ScrollTrigger.create({
      trigger: trigger.current,
      start: "top top",
      end: "bottom bottom",
      pin: pin.current
    })

 

    gsap.set(photos, { yPercent: 101 })

 

    details.forEach((detail, index) => {
      const animation = gsap.timeline()
        .to(photos[index], { yPercent: 0 })
        .set(allPhotos[index], { autoAlpha: 0 })
      ScrollTrigger({
        trigger: `.hd-${index}`,
        start: "top 80%",
        end: "top 50%",
        animation: animation,
        scrub: 1,
        markers: true
      })
    })
  }, [])

 

  return (
    <>
      <div className="w-full flex">
        <div ref={trigger} className="w-1/2">
          {
            list.map((item, index) => {
              return (
                <TextBox title={item.title} index={index} desc={item.desc} key={index} />
              )
            })
          }
        </div>
        <div ref={pin} className="w-1/2">
          <div className="w-full h-screen flex justify-center items-center">
            <div className="w-[40vw] relative aspect-square shadow-2xl rounded-lg overflow-hidden">
              {
                list.map((item, index) => {
                  return (
                    <>
                      <div id="photo" key={index} className={`w-full h-full absolute ${item.color}`}></div>
                    </>
                  )
                })
              }
            </div>
          </div>
        </div>
      </div>
    </>
  )
}

 

function TextBox({ title, desc, index }) {
  return (
    <>
      <div id="details" className="h-[100vh] flex flex-col items-center justify-center gap-8">
        <h2 className={`headline hd-${index} text-5xl`}>{title}</h2>
        <p className="text-center w-1/2">
          {desc}
        </p>
        <Button>Explore</Button>
      </div>
    </>
  )
}

See the Pen vYVBPJq by snorkltv (@snorkltv) on CodePen

Link to comment
Share on other sites

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

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

 

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

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

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

Hi @Iischeese welcome to the forum and thanks for being a club member!

 

We love to see what you can come up with in a minimal demo so that we can beter understand your thought process and thus better help you understand the tool. Above are some links to Stackblitz templates so that you can directly work in your frame work of choice. (here is the Next.js version) 

 

I've written a guide how you can create these kind of card stacking effects, see the blog post here. And a demo below that uses that logic with a similar effect that you want. If you still need help please show us what you've tried in something like Stackblitz and someone here will be happy to point you in the right direction. Hope it helps and happy tweening! 

 

See the Pen abMbwYd by mvaneijgen (@mvaneijgen) on CodePen

 

  • Like 2
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.
×
×
  • Create New...