2014-10-28 4 views
-1

나는이 객체가 항상 왼쪽 구석에 있지만, 객체를 div container으로 드래그 앤 드롭 할 수있었습니다. 나는 커서 포인터가있는 곳에서 오브젝트를 어떻게 배치 할 수 있는지 알고 싶습니다.jQuery ui 마우스 위치에서 드래그 앤 드롭

문제는 JSFiddle에서 볼 수 있습니다.

나는이 솔루션은 다음 코드 조각이 될 수 있음을 이해한다 :

$clone.removeClass('label-item') 
     .removeClass('ui-draggable') 
     .addClass('dragIt') 
     .css('height', 'auto') 
     .css('width', 'auto'); 

그리고 나는 아마 ui.offset에 따라 lefttop 위치를 추가해야?

+0

중복 가능성 [JQuery와-낙하 할 UI를 사용하는 위치가 드래그 & 드롭 추가 항목 (http://stackoverflow.com/questions/16607275/positioning-of-dragged-dropped-appended-items-을 사용 - jquery - ui - droppable) – isherwood

답변

0

해결되었습니다.

var positionX = ui.offset.left - $container.offset().left; 
var positionY = ui.offset.top - $container.offset().top; 

$clone.css('left', positionX + 'px') 
     .css('top', positionY + 'px');