2013-03-01 2 views
0

이미지를 드래그 할 수 있도록 설정하는 데 문제가 있습니다.이미지를 동적으로 드래그 가능으로 설정하십시오.

var thumb = document.createElement("img"); 
thumb.setAttribute('draggable', "true"); 

내가 만들고 같이 DOM에 내 이미지를 추가 : 이 코드는 작동하지 않는 것 var에 엄지 손가락 = document.createElement ("IMG");

 thumb.setAttribute('draggable', "true"); 
     thumb.setAttribute('alt', label); 
     thumb.setAttribute('id', "dhmvseries_" + label); 
     thumb.setAttribute("dhmvseriesuuid",label); 

     thumb.ondragstart = thumbDragStart; 
     thumb.ondragend = thumbDragEnd; 
     thumb.onmouseover = displayThumbInfo; 
     thumb.onmouseout = hideThumbInfo; 

var thinner = createElement("div", "dhThumbImage dhRounded"); 
thinner.appendChild(thumb); 
+0

문제를 밝히기 위해 지금까지 시도했거나 조사한 내용은 무엇입니까? jsfiddle http://jsfiddle.net을 게시 하시겠습니까? –

+1

DOM 트리에 요소를 추가하고 있습니까? 'src' 속성을 설정하고 있습니까? 여기에 좀 더 많은 정보와 코드가 필요합니다. 바이올린을 설정하십시오. _ "이 코드는 작동하지 않는 것 같습니다"_는 다소 모호합니다. 무엇을 보았고 무엇을 기대합니까? –

+0

img는 기본적으로 드래그 가능하며 이미지를 가져 와서 이동하십시오. – Toping

답변

0

저는 공용 건물에서 사용하고 있습니다.이 건물은 폐쇄 컴파일러와 함께 사용하기위한 것입니다.

/** drag(node n, property p) 
* sets dataTransfer text to value of property p when node n is dragged 
**/ 
function drag(n,p){n['draggable']=1 
    n['ondragstart']=function(a){a.dataTransfer.setData("Text",a.target?a.target[p]:a.srcElement[p])}} 

/** drop(node n, function f) 
* sets a drop event handler for node n that uses function f as its handler 
* function f will be passed: the target node and the dataTransfer "Text" value 
ex. var f=function(t,s){t.style.backgroundColor=s} //sets background the Text value 
* * the "Text" is set to the value of property p in the drag event 
* see drag(node n, property p) 
**/ 
function drop(n,f){n['ondragover']=F 
    n['ondrop']=function(a){f(n,a.dataTransfer.getData("Text")) 
    return!!0}} 
관련 문제