Jump to content
GreenSock

cormack

Draggable basic question

Recommended Posts

Hi,

 

Continue my learning process im planning to do some tests with the draggable option.

 

My first question is: without being yet a memeber of the Green Sock Club, i can use draggable options except some more advanced right?

 

In case that i can... i want to be able to select any visible Dom element (or most common like divs, images, etc) on my page and drag it to a different place on the document or just to select that visible Dom element..

 

How can achieve that? Right now i am using a class to make object selectable to drag, if i use * instead, it selects the document also.

Maybe there is another more efficient way, in fact i don't know if using Draggable.create(".mobil");  inside the function is a good coding standard, but if i don't do it it does not works.

 

 

Any idea will be welcome.

 

Thanks

 

 

 

See the Pen pJBmLX by Cormack (@Cormack) on CodePen

Link to comment
Share on other sites

I think you meant to do something like this:

Draggable.create(".class1", {
  onPress:function() {
    $(this.target).addClass("mobil");
  },
  onRelease: function() {
    $(this.target).removeClass("mobil");
  }
});

Right?

 

And yes, you can use Draggable without being a Club GreenSock member. You just don't get the throwProps functionality (smooth momentum-based deceleration when flicking). 

 

Enjoy!

  • Like 2
Link to comment
Share on other sites

Thanks!!

 

Just one question: will this work if latter i add a new element with class "class1"?

Will this works for elements added at runtime to the Dom?

Link to comment
Share on other sites

No, you'd need to create() a Draggable for that new element that gets added. Draggable doesn't constantly watch for changes to the DOM and automatically create new instances for you (that'd be bad for performance)

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.
×