I have an SVG object. I want this to be dragged and dropped in an area where it will be engaged. I exchanged the document.body
through my "#name of svg object"
, but that does not work. I heard the problem with the SVG is the dragging offset? Because of top: e.pageY
and left: e.pageX
, but I do not know why. I tried it with translate and mouse but it doesn't work.
$(document).ready(function() {
var $dragging = null;
$(document.body).on("mousemove", function(e) {
if ($dragging) {
$dragging.offset({
top: e.pageY,
left: e.pageX
});
}
});
$(document.body).on("mousedown", function (e) {
$dragging = $(e.target);
console.log($dragging);
});
$(document.body).on("mouseup", function (e) {
console.log($dragging);
$dragging = null;
});
})