问题
I am using Snap.svg library and doing some drag & drop. My question is how do i get id of element that i am dragging over. I am trying to implement drag and drop and only selected areas are valid drop targets. I do not know how to check upon dragend what element is underneath my drag. This is from documentation:
Element.drag(onmove, onstart, onend, [mcontext], [scontext], [econtext])
When element is dragged over another element drag.over.id fires as well
How do i listen for drag.over.id?
My code:
Snap.load("images/drag-drop.svg", function (f) {
Snap('.state-02').append(f);
});
var s = Snap(".state-02 svg");
var origTransform;
var dropZone = Snap('#drop-zone');
var block = s.rect(100, 100, 100, 100, 20, 20);
block.attr({
fill: "rgb(236, 240, 241)",
stroke: "#1f2c39",
strokeWidth: 3,
id : 'box'
});
block.drag(
function onThisDrag(dx, dy, x, y, e) {
this.attr({
transform: origTransform + (origTransform ? "T" : "t") + [dx, dy]
});
},
function onThisDragStart(x, y, e) {
origTransform = this.transform().local;
console.log('start drag');
},
function onThisDragEnd(event) {
console.log(event);
});
来源:https://stackoverflow.com/questions/29490261/snap-svg-how-to-get-what-element-we-are-dragging-over