2013-03-01 4 views
0

У меня возникают проблемы с настройкой моего изображения для перетаскивания. Этот код не похоже на работу:Устанавливать динамически динамическое изображение

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

создать и добавить мое изображение в DOM так: вар палец = 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}} 
Смежные вопросы