Amar Singh
Amar Singh

Reputation: 5622

Restrict a smooth drag in draggable jquery-ui

I am dragging a div within a main div with respect to y-axis.

$("#childdiv").draggable({axis:'y'});

It drags smoothly in y axis. But I want a drag with jerks..

For Example : When I start drag .. the draggable component directly moves to 50px and if I again drag next jump will be to 100px next drag will directly jump to 150px . It should be simillar like sortable with placeholder but using draggable.

Upvotes: 0

Views: 710

Answers (1)

blgt
blgt

Reputation: 8205

You can use the grid option to get this:

Snaps the dragging helper to a grid, every x and y pixels. The array must be of the form [ x, y ].

eg.

$("#childdiv").draggable({
    axis:'y',
    grid: [0, 50]
});

Here's an example fiddle: https://jsfiddle.net/g1epL4ea/

Upvotes: 1

Related Questions