Advertisement
ygeorgiev

Multiple Draggable

Jul 6th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.04 KB | None | 0 0
  1. $(function () {
  2.     gridX = 1; //1 to default
  3.     gridY = 1; //1 to default
  4.     $('#draggable> *').draggable({
  5.         grid: [ grid, gridY ],
  6.         distance: 20,
  7.         containment: '#parent',
  8.         start: function(event, ui) {
  9.             selectedObjs = $('div.ui-selected').filter('[id!='+$(this).attr('id')+']');
  10.             delete startPos;
  11.         },
  12.         drag: function(event, ui) {
  13.             var currentLoc = $(this).position();
  14.             var start = ui.originalPosition;
  15.             var offsetLeft = currentLoc.left-start.left;
  16.             var offsetTop = currentLoc.top-start.top;
  17.  
  18.             moveSelected(offsetLeft, offsetTop);
  19.         }  
  20.     });
  21.  
  22.     function moveSelected(ol, ot) {
  23.         selectedObjs.each(function() {
  24.             if(typeof(startPos) == 'undefined') {
  25.                 startPos =$(this).position();
  26.             }
  27.             $(this).css('left', Math.floor((startPos.left+ol)/gridX)*gridX);
  28.             $(this).css('top', Math.floor((startPos.top+ot)/gridY)*gridY);
  29.         });
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement