我给出的图像是:
<img src = "images/dress_1.jpeg" draggable="true" ondragstart="drag(event)" />
并给出动力学 div 之类的:
<div id="container" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
// of course in <script>
var stage = new Kinetic.Stage({
container: 'container',
width: 600,
height: 600,
});
我有一个以图像为模式的矩形,例如:
var rectArea_1 = new Kinetic.Rect({
fillPatternImage: images.topLeft, //in sources, {topLeft: 'http://...', ...}
});
然后在js中:
function allowDrop(ev)
{
ev.preventDefault();
}
function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}
function drop(ev)
{
ev.preventDefault();
data = ev.dataTransfer.getData("Text");
img_received = document.getElementById(data);
}
对于 drop 函数,我想如果我添加这样的两行:
function drop(ev)
{
ev.preventDefault();
data = ev.dataTransfer.getData("Text");
img_received = document.getElementById(data);
sources.topRight = img_received.src;
loadImages(sources, function(images) {draw(images);});
}
它会起作用,但我试图将最后两行放入:
rectArea_2.on('dragend', function() {
sources.topRight = img_received.src;
loadImages(sources, function(images) {draw(images);});
});
但这不起作用。有什么建议么?谢谢