Skip to content

Instantly share code, notes, and snippets.

@aramboyajyan
Created May 26, 2018 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aramboyajyan/dffd6ce703d977e475411fb0ffb79287 to your computer and use it in GitHub Desktop.
Save aramboyajyan/dffd6ce703d977e475411fb0ffb79287 to your computer and use it in GitHub Desktop.
Combining jQuery UI selectable and draggable
$(function () {
'use strict';
var selected = $([]), offset = {top: 0, left: 0};
$("#container").selectable();
$("#container div").draggable({
snap : true,
start: function () {
if (!$(this).is(".ui-selected")) {
$(".ui-selected").removeClass("ui-selected");
}
selected = $(".ui-selected").each(function () {
var element = $(this);
element.data("offset", element.offset());
});
offset = $(this).offset();
},
drag: function (event, ui) {
var draggedTop = ui.position.top - offset.top, draggedLeft = ui.position.left - offset.left;
selected.not(this).each(function () {
var element = $(this), off = element.data("offset");
element.css({top: off.top + draggedTop, left: off.left + draggedLeft});
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment