Jump to content
Search Community

Draggable onDragScope issues

affka test
Moderator Tag

Recommended Posts

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

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();
  }
  ...
});

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...