2014-05-23 3 views
1

끌어서 놓기 응용 프로그램에서 작업하고 어떤 개체가 이벤트를 기반으로하는지 혼란스러워집니다. 내가 드래그를 초기화 예를 들어 내가 다시 드래그 통화 실행하고 그래서 자신의 위치를 ​​추적 할 수있는 UI를 전달하는 기능을 설정 :jQuery UI 끌어서 놓기 개체 - ui, ui.helper와 this의 차이점

jQuery('.drag').draggable({ 
     helper : 'clone', 
     drag : function (event, ui) { test(ui.helper, ui, this);} 
}); 

function test(helper, drag_ui, drag_this){ 

    //check the type of each, and as expected each are objects 
    console.log('HLEPER TYPE: '+jQuery.type(cln_h));//object 
    console.log('UI TYPE: '+jQuery.type(cl));//object 
    console.log('THIS TYPE: '+jQuery.type(this_elem));//object 

    //lets try and get the top position of each 
    console.log('helper.position.top: '+helper.position.top);//undefined 
    console.log('drag_ui.position.top: '+drag_ui.position.top);//working 
    console.log('jQuery(drag_this).position.top: '+jQuery(drag_this).position.top);//undefined 


    //So, the ui parameter gives us a result, ui.helper nothing, and this nothing. 
    //However, if I get the position() of the helper and this first, then I get results. 


    //get pos first 
    helper_pos = helper.position(); 
    console.log('helper_pos.top: '+helper_pos.top);//working 

    drag_this_pos = jQuery(drag_this).position(); 
    console.log('drag_this_pos.top: '+drag_this_pos.top);//working, but different result 

    //So now i have some results, but the weird thing is that drag_this is different to ui, and ui.helper. 
} 

내가 원하는 것은 정상 위치를 알고하는 것입니다 경우 도우미 클론 나는 그것을 끌고있다. 내가 본 다른 사례는이 세 가지 중 하나를 사용합니다 : ui, ui.helper and this. 내가 알고 싶은 것은 :

  1. 그들 모두의 차이점은 무엇입니까? 그것들은 모든 대상이지만 다른 속성입니까?
  2. 이 시나리오에서 가장 좋은 방법은 무엇입니까?

조금만 배우면 좋겠다.

감사합니다.

답변

1

차이점은 미묘하지만 시나리오에 따라 다릅니다. helper을 사용하는 경우 고려해야 할 차이점을 기술하십시오. 우리는 당신이 복제를 드래그하는 동안 clone helperdraggable이 위치에 계속 사용하는 경우http://jsfiddle.net/6UL5A/2/

:

도우미를 사용.

- 검색 ui 또는 ui.helper 위치는 helper 위치에 모두 동일한 결과가 나타납니다.

- 검색 this 위치는 selector 위치가되며 복제본이 아닙니다. 도우미없이

: 여기http://jsfiddle.net/6UL5A/3/

우리는 다른 시나리오는, 우리의 draggable 선택 주위에 이동이 있고, 단지 그것의 복제.

- 검색 ui은 시작 위치와 관련하여 selector 위치를 가져옵니다.

- 검색 ui.helper 또는 this은 전체 뷰포트와 관련하여 selector 위치를 가져옵니다. 말했다와


최고의연습는 설계 요구에 적합한 하나입니다.