0
드래그 할 수있는 요소의 초기 위치를 저장하고 이후 드래그 한 위치의 위치를 결정한 다음 그 이후에 요소를 원래 위치로 되돌릴 방법이 있습니까?jQuery UI 드래그 가능한 요소의 위치 저장
드래그 할 수있는 요소의 초기 위치를 저장하고 이후 드래그 한 위치의 위치를 결정한 다음 그 이후에 요소를 원래 위치로 되돌릴 방법이 있습니까?jQuery UI 드래그 가능한 요소의 위치 저장
매개 변수의 stop
이벤트와 originalPosition
값을 원래 위치로 사용할 수 있습니다.
$(".drag").draggable({
stop: function(event, ui) {
console.log(ui.originalPosition)
$(this).animate(ui.originalPosition)
}
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.0/css/smoothness/jquery-ui-1.10.0.custom.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.0/jquery-ui.js"></script>
<div style="width: 50px; height: 50px; border: 1px solid red;" class="drag"> Drag Me! </div>
<div style="width: 50px; height: 50px; border: 1px solid green;" class="drag"> Drag Me! </div>
당신이 여기
originalPosition
의 값$(this).animate
을 사용하여 해당 위치에있는 요소를 이동할 수 있습니다 것이 그 예이다