affka Posted July 21, 2020 Share Posted July 21, 2020 Hi! I have a class which has a property "dragger". To this dragger property I assign GSAP Draggable new instance: this.dragger = new Draggable(element, { bounds: ".container", edgeResistance: 0.65, type: "x,y", inertia: true, autoScroll: true, liveSnap: true, onDragEnd: _self.onDragEnd, onDragStart: _self.onDragStart, onDrag: _self.onDrag, onDragScope: this, }); As above, you can see there is a settings of "onDragScope" set to "this" (I have tried to set "this" to "_self" variable outside and then assign it but same result). When running onDrag runs, it logs me a GSAP Draggable instance instead of the class which has "dragger" property. Any ideas why? onDrag() { console.log("drag", this); // logs GSAP Draggable instead of class } Thanks for the ideas. Link to comment Share on other sites More sharing options...
GreenSock Posted July 21, 2020 Share Posted July 21, 2020 There is no such thing as onDragScope, but you have several other options. You can set the callbackScope instead (which would apply to all callbacks) or you can do the trick you referenced in your posts, creating a variable that references "this" like: let self = this; this.dragger = new Draggable(element, { onDrag() { self.onDrag(); } ... }); 2 1 Link to comment Share on other sites More sharing options...
ZachSaucier Posted July 21, 2020 Share Posted July 21, 2020 As Jack said, onDragScope doesn't exist any longer as of GSAP 3. We simplified the callback scopes. See the release notes for more info: 2 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