3

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);

});
Community
  • 1
  • 1
Luka Mis
  • 543
  • 1
  • 7
  • 18
  • I have a feeling in the source that the drag over stuff is commented out, so not sure that documentation is correct. I would check that first. – Ian Apr 07 '15 at 12:49

0 Answers0