taye / interact.js

JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE9+)
http://interactjs.io/
MIT License
12.38k stars 785 forks source link

Snap to fixed position after inertia #19

Closed mathew-kurian closed 10 years ago

mathew-kurian commented 10 years ago

How do we snap to a certain position once the drag position reaches some distance away from the snap point?

i.e. In the drag progress bar example you have, if you reach near 0 - 5%, then it will snap to 0% after the inertia bounce. Is it possible to have multiple snap points each snap point consisting of a position and a radius (around the position for which element will be snapped into the position)

If this is not a feature already, I can try and add it in.

taye commented 10 years ago

I think that for what you described can use either anchor or path mode:

interact(element).snap({
    mode: 'anchor',
    anchors: [
        { x:  0, y: 0, range: 10 },
        { x: 20, y: 0, range:  5 },
        ...
    ]
});

Using path functions gives you the greatest control as you can have multiple functions and can return whatever snap coordinates you want.

interact(element).snap({
    mode: 'path',
    paths: [
        // x and y args are the unsnapped coordinates
        function (x, y) {
            // return an object with x, y and/or range properties
        },
        ...
    ]
});

I'm not sure that I fully understand what you're describing. If I haven't answered your question please give me some more details.

taye commented 10 years ago

Here is the documentation for the different snapping settings: http://interactjs.io/docs/#Interactable.snap

taye commented 10 years ago

Is this still an issue for you? If it is can you provide some more information otherwise this issue can be closed?

sbulink commented 6 years ago

Hi @taye, ive been trying to rerun the snap to grid function, after performing a drag move with a new element to the grid, so that all elements (children of parent div), align to grid. As now elements stack on top of each other not only next to each other,

sbulink commented 6 years ago

++great lightweight library by the way,