Created
May 26, 2018 13:08
-
-
Save aramboyajyan/dffd6ce703d977e475411fb0ffb79287 to your computer and use it in GitHub Desktop.
Combining jQuery UI selectable and draggable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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