I'm a novice to HTML5 and I'd welcome any background information on understanding how the drag-over behavior is supposed to work in Snap.svg. I've learned how to drag complex SVG images that I've drawn in Adobe Illustrator. See the dragging code below (I hope it is of use). Next, I'm trying to detect when my dragged SVG is placed correctly over another loaded SVG image, which I assume would require a behavior in the the dragging event listener and in the stopDrag event listener. I have no clue of how to detect what my dragged object is passing over. Any help or references or corrections are welcome.
Thanks,
Snap.load("../svg/productimage.svg", function (f) { //load a highly detailed, realistic-looking SVG that was created in Adobe Illustrator
g = f.select("g");
s.append(g);
g.transform('t40, 140'); //transform to place the product image (this is the only way I can find to change the x and y coordinates of a complex, imported SVG)
g.cx = 40; //attach the image's known coordinates where the drag event handlers can find them (this was easier than trying to parse the transform string)
g.cy= 140;
g.ox = 0; //coordinates used to hold the difference between my product image and the point that the mouse clicks it
g.oy = 0;
g.drag( dragging, startDrag,
function () {
//I thought a drop or drag over behavior would go here, but I don't know how to detect a drop-over or drop event
});
});
startDrag = function(posx, posy){ //drag start handler assigned to all product images
this.ox = posx -
this.cx; //capture the offset between the mouse's coordinates and store it with the object
this.oy = posy -
this.cy;
}
dragging = function(dx, dy, posx, posy){ //dragging handler
this.cx = posx - this.ox; //subtract offset from mouse position to keep dragged object tracking with the mouse
this.cy = posy - this.oy;
t = 't' +
this.cx + ',' +
this.cy; //build and apply a transform
this.transform(t);
}