Answer the question
In order to leave comments, you need to log in
How to drag SVG with mouse?
There is a circle on the svg canvas, how can I move it with the mouse?
Please tell me some plugin without JQ
Answer the question
In order to leave comments, you need to log in
ball.addEventListener('mousedown', function(evt) {
svg.addEventListener('mousemove', drag)
})
ball.addEventListener('mouseup', function(evt) {
svg.removeEventListener('mousemove', drag)
})
svg.addEventListener('mouseleave', function(evt) {
svg.removeEventListener('mousemove', drag)
})
function drag(evt) {
let x = evt.x - ball.cx.baseVal.value
let y = evt.y - ball.cy.baseVal.value
ball.setAttribute('transform', 'translate(' + x + ', ' + y + ')')
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question