njvan Posted February 22, 2022 Share Posted February 22, 2022 Hey all, I'm playing around with GSAP trying to get a Guitar Hero-style effect work. The note div gets added to the tracks (the four vertical columns) successfully at the right time (with tl.call and tl.set), but tl.fromTo isn't working as the element can't be found. Any idea why? Thanks for the assist. function addToDom(track, i) { var innerDiv = document.createElement('div'); innerDiv.className = 'note'; innerDiv.setAttribute("id", "note" + i); const iDiv = document.getElementById("track" + track) iDiv.appendChild(innerDiv); } function addtoTL() { for (i = 0; i < this.testNoteTrack.length; i++) { tl.call(addToDom, [this.testNoteTrack[i].track, i], null, this.testNoteTrack[i].time); var elementName = "note" + i; tl.set(elementName, {top: -150}, this.testNoteTrack[i].time); tl.fromTo(elementName, {top: -150}, {top: this.viewHeight + 150, duration: 2, ease: "none"}); } tl.play(); } Link to comment Share on other sites More sharing options...
GreenSock Posted February 22, 2022 Share Posted February 22, 2022 Hi @njvan. Welcome to the forums. We'd be happy to take a peek if you can provide a minimal demo - it's just not feasible to glance at a small code snippet and accurately diagnose the issue. My guess is that your "elementName" variable isn't legitimate. Perhaps you meant to prepend it with "#" because it's an ID? In other words, a selector like "note1" isn't valid - maybe you meant "#note1" or ".note1" (id or class)? Link to comment Share on other sites More sharing options...
njvan Posted February 23, 2022 Author Share Posted February 23, 2022 11 hours ago, GreenSock said: Hi @njvan. Welcome to the forums. We'd be happy to take a peek if you can provide a minimal demo - it's just not feasible to glance at a small code snippet and accurately diagnose the issue. My guess is that your "elementName" variable isn't legitimate. Perhaps you meant to prepend it with "#" because it's an ID? In other words, a selector like "note1" isn't valid - maybe you meant "#note1" or ".note1" (id or class)? Thanks for the welcome and the link to set-up a pen! I have done so here: See the Pen eYeKypy by njvan (@njvan) on CodePen Thanks for the assist! Link to comment Share on other sites More sharing options...
Solution OSUblake Posted February 23, 2022 Solution Share Posted February 23, 2022 Hi njvan, You have a lot of issues going on there, let's try to unpack this. First, you are mixing old and new syntax. How to convert to the latest version can be found in the Migration Guide. Second, you are trying to create an animations for elements that don't exist at the time of creation. This is very similar to a question asked here. Syntax wise, I would avoid using this unless it's in the proper context. Just reference whatever you are trying to use by name. And I would also animate using y instead of top for better performance. See the Pen WNXyMYP by GreenSock (@GreenSock) on CodePen 4 Link to comment Share on other sites More sharing options...
njvan Posted February 23, 2022 Author Share Posted February 23, 2022 Thanks so much for the information as well as the solution. I hadn't realised I was mixing syntax. Very much appreciated! 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