2013-02-22 3 views
0

전체 페이지에서 요소를 드래그 할 수있게 만드는 방법. 이제는 부모 div 내에서 요소 만 드래그 할 수 있습니다. 이 일을해야 http://touchpunch.furf.com/JQuery draggable containment

var thumb = document.createElement("img"); 
      $(thumb).draggable({containment: "html"}); 
      thinner.appendChild(thumb); 

답변

2

:

$(thumb).draggable() 

나는이 librarary을 사용하고

$(thumb).draggable({containment: "body"}); 

Official demo on the containment option

+0

나를 위해 작동하지 않습니다 : S – Jacob

+0

잘 모르겠어요,하지만 touchpunch 라이브러리에 대한 일을 할 수있다 이 경우? – techfoobar

+0

동적으로 이미지를 만들고 dragablle 옵션을 적용했지만 작동하지 않습니다. – Jacob

1

당신이 $(thumb).draggable({containment: "body"});을 사용하려는 경우, 당신은이를 추가해야합니다 CSS에.

body{ 
    overflow: hidden; 
} 

그렇지 않으면 사용 (CSS 없음)

$(thumb).draggable({containment: "html"}); 

DEMO : (CSS와) http://jsbin.com/ukotit/7/edit

데모 : 봉쇄 외에도 http://jsbin.com/ukotit/5/edit

+0

죄송하지만 작동하지 않습니다! 원하는 경우 스크린 샷을 붙여 넣을 수 있습니다! – Jacob

+0

코드를 입력하십시오. 그러면 살펴 보겠습니다. – Dom

1

, 당신 appendTo 옵션을 사용해야 할 수도 있습니다. 당신이 그것을 드래그하는 동안 도우미는 몸에 추가 한합니다 :

$(thumb).draggable({containment: "body", appendTo: "body"}); 

http://api.jqueryui.com/draggable/#option-appendTo

관련 문제