Jump to content
Search Community

Draggable snap not called

garyw test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

I'm trying to use a snap function with Draggable. The snap property is not listed in the list of configuration properties in the documentation. I've found examples of using it but the function never gets called.

 

        const draggables = Draggable.create(draggersArray, {
            snap: {
                points: function(point){
                    console.log(point);
                    return point;
                }
            }
        });

I made sure to register the Draggable plugin, and I can start dragging items. But when I let them go, the snap function isn't called.

Link to comment
Share on other sites

I also tried this, but it still doesn't work:

 

        const draggables = Draggable.create(draggersArray, {
            snap: function(value){
                    console.log(value);
                    return point;
                }
         });

 

Link to comment
Share on other sites

  • Solution

Hey there!

 

I think you need inertiaPlugin to do snapping logic after the element's been released

from a demo in the docs 👀

Quote

snap: function(value) { //this function gets called by InertiaPlugin when the mouse/finger is released and it plots where rotation //should normally end and we can alter that value and return a new one instead. This gives us an easy way to //apply custom snapping behavior with any logic we want. In this case, we'll just make sure the end value snaps //to 90-degree increments but only when the "snap" checkbox is selected. return Math.round(value / 90) * 90;


See the Pen JjavZNz?editors=0011 by GreenSock (@GreenSock) on CodePen

  • Like 2
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...