나는 2x2 그리드 영역의 [[A, B] [C, D]] 그리드 아래에 draggables의 1x4 그리드가 있습니다. 나는 단지 서로 옆에 일정한 draggables를 원한다. 예를 들어, B에 draggable이 있고 다른 draggable을 A로 드래그하면 B에서 draggable을 되돌릴 수있는 방법이 있습니까? draggables에는 data-row 및 data-col이 있으므로 필요한 경우 이전/다음 열에서 draggable을 가져올 수 있습니다.다른 draggable을 떨어 뜨린 후 draggable 되돌리기
$(".draggable").draggable({
scroll: false,
snap: ".snaptarget",
snapMode: "inner",
stack: ".draggable",
revert: function (event, ui) {
var $draggable = $(this);
$draggable.data("uiDraggable").originalPosition = {
top: 0,
left: 0
};
return !event;
}
});
$(".snaptarget").droppable({
accept: ".draggable",
drop: function (event, ui) {
var $draggable = $(ui.draggable);
var $droppable = $(this);
// This droppable is taken, so don't allow other draggables
$droppable.droppable('option', 'accept', ui.draggable);
ui.draggable.position({
my: "center",
at: "center",
of: $droppable,
using: function (pos) {
$draggable.animate(pos, "fast", "linear");
}
});
// Disable prev or next droppable if the pagewidth == 1
if ($droppable.data("col") == 1) {
$droppable.next().droppable("option", "disabled", true);
var nextDrag = $(".draggable[data-row='" + $droppable.data("row") + "'][data-col='2']");
if (nextDrag.length) {
// I need to revert nextDrag if there is one.
// I've tried this but it doesn't seem to work
nextDrag.data("uiDraggable").originalPosition = {
top: 0,
left: 0
}
}
}
},
tolerance: "pointer"
});
다른 draggable의 '되돌리기'를 생각할 수있는 방법이 없습니다. 다음 요소를 검사하기 위해'stop' 또는'drop'을 체크 할 수 있습니다. 필요한 경우 bad div의 움직임을 시작 또는 원점에 애니메이션으로 적용 할 수 있습니다. – Twisty
@Twisty 나는 그 다음을 조사하고 있었지만 길이 있는지 확인하고있었습니다. 감사. – homes
'되돌리기'를 통해서가 아닙니다. 너는 바른 길을 가고있다. 테스트를 위해이 피들을 만들었습니다 : https://jsfiddle.net/Twisty/a4ucb6y3/ – Twisty