Try using the parameters inherent in the .draggable () function at http://jqueryui.com/demos/draggable/
basically it says that the snap parameter is set to true :
$( ".selector" ).draggable({ snap: true, snapMode:'outer', snapTolerance:40 });
snapMode "... determines to which edge of the anchor elements the dragged object is bound. It is ignored if the anchor is false. Possible values are" internal "," external "," both ". And snapTolerance -" ... The distance in pixels from the edges of the element bindings at which the binding occurs. "
Or try using the grid parameter. This is designed to do exactly what you want: "... the Grid anchors the drag and drop helper element to the grid, every x and y pixels. Array values: [x, y] Code examples":
Initialize the draggable with the specified grid option.
$( ".selector" ).draggable({ grid: [50, 20] });
Get or set the grid parameter after init.
//getter var grid = $( ".selector" ).draggable( "option", "grid" ); //setter $( ".selector" ).draggable( "option", "grid", [50, 20] );
Hope this helps you.
source share