Interagir em JS, arrastar elementos svg dentro de svg com viewbox?
Meu problema, quando eu arrasto elementos, o elemento fica muito atrás do cursor, então parece que é um problema de proporção potencialmente?
O código:
interact('.element', {
context: '.lipstick__plane'
})
.draggable({
snap: {
targets: [
interact.createSnapGrid({x: 10, y: 10})
],
range: Infinity
},
inertia: true,
restrict: {
restriction: '#lipstick__plane__main',
elementRect: {top: 0, left: 0, bottom: 1, right: 1},
endOnly: true
}
})
.on('dragmove', function (event) {
$scope.$apply(function () {
var target = event.target,
x = (parseFloat(target.getAttribute('x')) || 0) + ((1020 / window.outerWidth) * event.dx),
y = (parseFloat(target.getAttribute('y')) || 0) + ((1020 / window.outerHeight) * event.dy);
var indx = event.target.getAttribute('data-index');
_.set($scope.stage.elements[indx], 'meta.XCord', x);
_.set($scope.stage.elements[indx], 'meta.YCord', y);
});
});
Estou mergulhando lá, o que o aproximou do cursor, mas eu poderia estar tentando números o dia inteiro ...
Meu bloco svg init:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1024 1024" width="1024px" height="1024px" xml:space="preserve" id="lipstick__plane__main">
Uma coisa que eu acho que poderia ser um problema, mas duvido, é que o resumo angular acontece após uma solicitação para obter o novox
ey
atributo?