Snap.svg how to get what element we are dragging over

梦想的初衷 提交于 2019-12-13 14:42:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!