jquery - Allowing draggable to move only in 20px squares -



jquery - Allowing draggable to move only in 20px squares -

basically have 2 containers, background repeating box 20x20 pixels. want allow draggables able move if aligned these 20x20 squares. found solution suits reason doesn't quite work rest of code.

here's i've tried far:

drag: function( event, ui ) { var snaptolerance = $(this).draggable('option', 'snaptolerance'); var topremainder = ui.position.top % 20; var leftremainder =ui.position.left % 20; if (topremainder <= snaptolerance) { ui.position.top = ui.position.top - topremainder; } if (leftremainder <= snaptolerance) { ui.position.left = ui.position.left - leftremainder; } }

the problem don't want boxes touch when dropped within of containers. utilize next function

for(var i=1; i<=15; i++){ $('#box-' + i).droppable({ greedy: true, tolerance: 'touch', drop: function(event,ui){ ui.draggable.draggable('option','revert',true); } })

};

both of them work fine individually, don't :d. here's illustration of happens sometimes:

http://i.stack.imgur.com/yrbm7.jpg [sry, can't post images :(]

another nasty bug if placed right within container, box returns previous position, if wasn't allowed dropped there.

here's fiddle: http://jsfiddle.net/rb4qeq8k/4/

so question is, there other way of making boxes move in 20px steps they're aligned container's squares, doesn't bug one?

edit: came conclusion snaptolerance somehow bugs , checks cursor's moves not object position.

it's in doc !

http://jqueryui.com/draggable/#snap-to

$( "#draggable" ).draggable({ grid: [ 20, 20 ] });

jquery jquery-ui

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -