classikd Posted December 10, 2019 Share Posted December 10, 2019 Hello, I am trying to scale list elements depending on their data-attribute, here is what i have : <ul> <li data-percent="50">1</li> <li data-percent="75">2</li> <li data-percent="15">3</li> </ul> let tl = new TimelineMax() tl .staggerFromTo('[data-percent]', 0.25, { scaleX: 0 }, { scaleX: function(){ // i would like to return a dynamic value return 0.5 }}, 0.1); Is there a way to get the data attribute of the current element ? I can't find a solution. Thank you Link to comment Share on other sites More sharing options...
ZachSaucier Posted December 10, 2019 Share Posted December 10, 2019 Hey classikd, You can do that using the second parameter, which is the target: See the Pen qBEZqXM?editors=0010 by GreenSock (@GreenSock) on CodePen I highly recommend GSAP 3 though! In GSAP 3 it'd be: See the Pen YzPqprg?editors=0010 by GreenSock (@GreenSock) on CodePen 3 Link to comment Share on other sites More sharing options...
classikd Posted December 10, 2019 Author Share Posted December 10, 2019 Thank you Zach. I though the arguments didn't exist because i have tested the first, and its value were always 0. Is that normal ? See the Pen dyPMNPb by classikd (@classikd) on CodePen Not the case with gsap 3 apparently Link to comment Share on other sites More sharing options...
GreenSock Posted December 10, 2019 Share Posted December 10, 2019 Yes, that's normal for GSAP v2 and earlier because the stagger methods create ONE tween for EACH element in the array, so of course the index will always be 0 (that function gets called by each tween instance...and each tween only has ONE target). It's more intuitive in GSAP v3 since any tween can have a stagger. In v2, you'd need to use the "cycle" special property to get that behavior. If you need help with that, just let us know. 3 Link to comment Share on other sites More sharing options...
classikd Posted December 10, 2019 Author Share Posted December 10, 2019 Oh ok I understand now, thanks a lot for your help ! I think I am going to try GSAP version 3 ?? 2 Link to comment Share on other sites More sharing options...
GreenSock Posted December 10, 2019 Share Posted December 10, 2019 4 minutes ago, classikd said: I think I am going to try GSAP version 3 ?? Buckle your seatbelt. You're in for a fun ride. I think you'll like it. 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