gew Posted August 11, 2022 Share Posted August 11, 2022 const MARQUE_DATA = ["WEBSITE", "AR", "MOBILE APP", "IOT", "VR"]; const Marquee = ({ data }: { data: string[] }) => { const wrapper = useRef<HTMLDivElement>(null); const inner = useRef<HTMLDivElement>(null); const q = gsap.utils.selector(inner); useEffect(() => { gsap.to(q("span"), { x: 500, duration: 8, repeat: -1, }); }, []); return ( <div ref={wrapper} className={styles.marqueeWrapper}> <div ref={inner} className={styles.marqueeInner}> {data.map((text, i) => ( <span key={i}> {text} | </span> ))} </div> </div> ); }; the rendered span doesnt animate if i use map like the code above, but when i try to hardcode the spans like <span>FOO</span> <span>BAR</span> <span>BEAR</span> this it does work as expected. any help apreciated ! 1 Link to comment Share on other sites More sharing options...
GSAP Helper Posted August 11, 2022 Share Posted August 11, 2022 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. 1 Link to comment Share on other sites More sharing options...
elegantseagulls Posted August 11, 2022 Share Posted August 11, 2022 My guess is that the useEffect is running before your spans are rendered via the map function. I'd put a check in your useEffect to make sure they exist before adding the gsap code. Again, a minimal demo is very helpful to check this sort of stuff. 1 Link to comment Share on other sites More sharing options...
SteveS Posted August 11, 2022 Share Posted August 11, 2022 If it is the issue that @elegantseagulls suggests, which it probably is, then I would use a ref array instead to better keep track of when elements exist. The useArrayRef hook here: Makes it easy to do so. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now