Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
x0b

Draggable snap - can it be set after create?

Recommended Posts

Is it possible to update the snap array on a draggable instance to something else after creation?

 

Say I have the snap values set to an array, but then later some values in that array change, can I change the old snap array to the new array, therefore updating the snap values?

 

Thanks

Link to comment
Share on other sites

Yes, you can access the snap object through the Draggable instance's vars like so

someDraggable.vars.snap = [0, 100, 200, 300]

or

someDraggable.vars.snap.x = [0, 50, 100, 150]
someDraggable.vars.snap.y = [0, 10, 20, 30]

Here is an example

 

http://codepen.io/GreenSock/pen/AkbLj

Link to comment
Share on other sites

Hi Carl,

 

Thanks, I tried the above syntax but it didn't work. I now realise from your Codepen that appending [0] to the draggable instance var is what I needed to do to access the vars.

 

Thanks a lot

Link to comment
Share on other sites

Just to be clear, yes, the code above refers to to a specific Draggable instance.

 

The CodePen demo uses Draggable.create() which returns an array of Draggables which is why the [0] was necessary. It pulled the first Draggable from the array of Draggables. 

 

Glad you got it working.

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