How to get stage coordinates on drop event kineticjs
I've a 'p' elements with a text. This elements should be drop on the stage
with the mouse position when the 'drop event' been shoot. My code is:
Html code:
Element1
Element2
Element3
Element4
Element5
Javascript:
var stage,modsLayer;
stage = new Kinetic.Stage({
container: 'container',
width: $('#container').width(),
height: 600
});
stage.on('drop',function(e){
//get stage mouse position coordinates to insert a text
});
modsLayer = new Kinetic.Layer();
stage.add(modsLayer);
$('.kineticjs-content canvas').attr('id','canvas');
$('.kineticjs-content canvas').attr('ondrop','drop(event)');
$('.kineticjs-content canvas').attr('ondragover','allowDrop(event)');
function allowDrop(e)
{
e.preventDefault();
}
function drop(e){
stage.fire('drop');
}
function drag(e)
{
switch(e.target.tagName){
case "P":
e.dataTransfer.setData("comp_id",e.target.id);
e.dataTransfer.setData("comp_name",e.target.innerText);
e.dataTransfer.setData("tagName",e.target.tagName);
break;
}
No comments:
Post a Comment