Jump to content
Search Community

Use pinning to layer panels on top of each other as you scroll with reactjs.

DevNate test
Moderator Tag

Recommended Posts

You haven't been totally clear on what you have tried so far. I notice that there is a goToSection(i)function though.

 

I added a <div class="buttons"></div> at the top of the page. Then I included this js which creates a button for each panel (the panels are already defined in the demo). When you click a button, it triggers goToSection with the panel index:

 

const buttons = document.querySelector(".buttons")

panels.forEach((panel, i) => {
  const button = document.createElement('button');
  button.innerText = `Panel ${i+1}`;
  buttons.appendChild(button);
  button.addEventListener("click", () => goToSection(i))
})

See the Pen b5b64bcc1d7494f8af91d3cbe9c6d5d6?editors=0110 by EightArmsHQ (@EightArmsHQ) on CodePen

  • Like 1
Link to comment
Share on other sites

Hi @DevNate and welcome to the GreenSock forums!

 

To complement @eightarmshq great example, here is a fork of the codepen you linked to a React app using GSAP Context (we strongly recommend using it when integrating GSAP in a React/Next/Gatsby environment):

 

https://codesandbox.io/s/upbeat-river-b6poef?file=/src/App.js

 

For you and other users that might be interested, keep an eye in this thread 👀, since I'll create a fork of the codesandbox example using React Router as well, in order to have a working example that has routes in it.

 

Let us know if you have more questions.

 

Happy Tweening!

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, DevNate said:

line 13 kinda throws me off balance

Hi,

 

Basically I'm setting just one GSAP Context instance to be reused everywhere in the component and I'm using state to keep it through re-renders. You could use a useRef hook as well and it shouldn't be much difference. Using state prevents using ctx.current everywhere it's used.

 

Happy Tweening!

  • Like 1
  • Thanks 1
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...