다음은 jsfiddle의 링크입니다. 첨부 된 jsfiddle에서 velocity.js를 사용하여 드래그 가능한 SVG 요소를 만들었습니다. x 및 y 축을 따라 드래그하는 것은 매우 불규칙합니다. 충고는 내 부분 또는 속도에 실수인지 여부를 혼동합니다.velocity.js로 SVG 요소 애니메이션하기
http://jsfiddle.net/KashifMKH/v1xx9nd1/6/
document.addEventListener("mousedown", mouseDown);
document.addEventListener("mouseup", endMove);
var click = false;
var clickX, clickY;
var moveX = 0,
moveY = 0;
var lastMoveX = 0,
lastMoveY = 0;
function mouseDown(evt) {
evt.preventDefault();
var element = (typeof(window.event) !== 'undefined') ? evt.srcElement : evt.target;
if (element.id === "mycirc") {
click = true;
clickX = evt.clientX;
clickY = evt.clientY;
}
document.addEventListener("mousemove", moveboth);
return false;
}
function movexaxis(evt) {
var clx = evt.clientX - clickX;
moveX = lastMoveX + clx;
return moveX;
}
function moveyaxis(evt) {
var cly = evt.clientY - clickY;
moveY = lastMoveY + cly;
return moveY;
}
function moveboth(evt) {
setTimeout(function move() {
evt.preventDefault();
var a = document.getElementById("mycirc");
if (click) {
movexaxis(evt);
moveyaxis(evt);
Velocity(a, {
translateX: moveX
}, {
duration: "0ms"
});
Velocity(a, {
translateY: moveY
}, {
duration: "0ms"
});
Velocity(a, "stop");
}
});
}
function endMove(evt) {
click = false;
lastMoveX = moveX;
lastMoveY = moveY;
}
가능한 중복 (http://stackoverflow.com/questions/27704974/ [velocity.js하여 드래그 요소 애니메이션]를 움직이는 draggable-element-using-velocity-js) – ydaniv