Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function () {
- gridX = 1; //1 to default
- gridY = 1; //1 to default
- $('#draggable> *').draggable({
- grid: [ grid, gridY ],
- distance: 20,
- containment: '#parent',
- start: function(event, ui) {
- selectedObjs = $('div.ui-selected').filter('[id!='+$(this).attr('id')+']');
- delete startPos;
- },
- drag: function(event, ui) {
- var currentLoc = $(this).position();
- var start = ui.originalPosition;
- var offsetLeft = currentLoc.left-start.left;
- var offsetTop = currentLoc.top-start.top;
- moveSelected(offsetLeft, offsetTop);
- }
- });
- function moveSelected(ol, ot) {
- selectedObjs.each(function() {
- if(typeof(startPos) == 'undefined') {
- startPos =$(this).position();
- }
- $(this).css('left', Math.floor((startPos.left+ol)/gridX)*gridX);
- $(this).css('top', Math.floor((startPos.top+ot)/gridY)*gridY);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement