Paul123 Posted November 4, 2021 Share Posted November 4, 2021 Hi Guys! Is there a way in GSAP3 to retrieve the target object of a tween? example: gsap.to('.selector', { duration: 1, y: theTarget.offsetHeight} ) If I remember correcty, there is a utility function in GSAP that retrieves the target DOM. That way you don't have to type the selector again. Thank You!! Link to comment Share on other sites More sharing options...
OSUblake Posted November 4, 2021 Share Posted November 4, 2021 Welcome the forums @Paul123 You can use function based values for that. The first parameter is the index of the element, and the second parameter will be the element. gsap.to('.selector', { duration: 1, y: (i, el) => el.offsetHeight }) 1 Link to comment Share on other sites More sharing options...
Paul123 Posted November 4, 2021 Author Share Posted November 4, 2021 Thank You! I didn't thought of that one! Will def go with this route! PS: But yeah, I remember GSAP having a way of accessing the target object - it's something that's not in the docs i think. If I'm not mistaken, I used "it" when I was working with GSAP Draggable. It's like a shortcut or something 😅 Link to comment Share on other sites More sharing options...
OSUblake Posted November 4, 2021 Share Posted November 4, 2021 There are other ways to get elements, like with this.targets(), but that's more for callbacks, like onComplete. And then there is the toArray util, which is useful when you want to do a loop. Draggable is a little bit different, and you can always get the target with this.target inside a Draggable callback. 2 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