garyw Posted March 15, 2023 Share Posted March 15, 2023 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 More sharing options...
garyw Posted March 15, 2023 Author Share Posted March 15, 2023 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 More sharing options...
garyw Posted March 15, 2023 Author Share Posted March 15, 2023 Here's a codepen: See the Pen poOVVYe by og-elmonty (@og-elmonty) on CodePen Link to comment Share on other sites More sharing options...
Solution Cassie Posted March 15, 2023 Solution Share Posted March 15, 2023 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 2 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