Jump to content
Search Community

Struggling with GSAP in Frontity/WP Environment

AGW test
Moderator Tag

Recommended Posts

Hey guys, I'm very new here (& not all that great with programming) - long time lurker, big admirer of GSAP and happy be in the club! I'm hoping somebody here can help me figure out what I'm doing wrong. 

 

I'm basically attempting to convert this simple CodePen into Frontity/React (embed at bottom of post). 

 

 

Here's the link to my CodeSandbox

https://codesandbox.io/s/xenodochial-saha-mfj42?file=/packages/mars-theme/src/components/test-scroll.js

 

The errors I get seem to come from my scroll-test.js file. No matter what I do, I can't seem to get any ScrollTrigger action (or even basic 'to' motion).  There have been some phantom moments once I've changed some code to target a different element, the page instantly begins to animate - but after I refresh, I'm given fatal errors instead. Not really sure what that is...

 

If I attempt to target certain elements, it won't run.

image.png.9a488b8b0d8f23259f97c7dd59b8de0f.png

 

If I target a previously declared component, it at least runs - but it claims scrollTrigger is an invalid property

image.png.008eed5796d18d1e479506df5e85f14b.png

 

I'm left to believe that GSAP isn't properly firing. Any ideas for troubleshooting this problem?

Happy to supply any additional information requested. I tried to follow the rules and created my problem on codesandbox, since it was the only service that had Frontity available.

 

Cheers,

AGW

 

 

 

See the Pen QWGwQYv by agw421 (@agw421) on CodePen

Link to comment
Share on other sites

I'm currently looking into React Refs:

https://reactjs.org/docs/forwarding-refs.html

 

The big problem I'm having is targeting a child dom element from within a react component. If I was able to target the H3 inside of the Section component, I'd be able to test GSAP's functions further.

 

This might be tough for me to pull off, but I'm diving in right now!

Link to comment
Share on other sites

Hey AGW and welcome to the GreenSock forums.

 

I've never heard of Frontify. Have you already read through the article about getting ScrollTrigger working with React in our learning section? I think they would greatly help you understand how to set things up. I also think our modules installation video and the install helper on the installation page would help you out. To be honest I think you going through those materials will help you understand better than us fixing your issues for you :) But if you go through them and have a specific question about GSAP let us know and we'll do our best to help.

Link to comment
Share on other sites

Thanks @ZachSaucier

 

I appreciate the help! The article you brought up is actually why I mentioned React Refs. While her example isn't built with Frontity in mind, I'm hoping I can figure out the translation points by going back and forth between all these learning sections. Not as easy for a beginner, but I'm trying here. I only asked after going through all of your and their documents - I'm not the type to expect others to do my work for me lol.

 

What makes this sticky is what I mentioned above: Targeting children DOM elements from within a component seems to be a requirement to figure this out.

 

Oh, and it's Fronti-TY not -FY. It's a React framework and port of WordPress. Fairly new, but serves the purposes my clients need without limiting the experience.

 

Link to comment
Share on other sites

Hi,

 

As Zach mentions, this is related to the way Styled Components work, but lucky for us, they have made some strides in order to facilitate the access to the actual DOM nodes.

 

Basically you have to pass a ref to the styled component you want to target in your GSAP instances, store that using the useRef hook and then just use ref.current in order to access the DOM node. This is a super simple example that takes the code from your file, without any errors:

 

https://codesandbox.io/s/gsap-scrolltrigger-styled-components-pzqy2

 

Hopefully this helps you get your site going.

 

Happy Tweening!!!

  • Like 4
Link to comment
Share on other sites

  • 4 weeks later...

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...