Vladimir
Vladimir

Reputation: 11

How make custom drag event in svg.js

I'm new to programming. I'm making something like vector editor with svg.js I've read documentation and didn't understand how to make custom events at all. Can you guys show an example of drag event?

Actually i'm trying to achieve elements to be removed on drag. For example i want to make tooltip following mouse cursor, that outputs current mouse coordinates. But it gets duplicated every onmousemove event.

Upvotes: 0

Views: 1404

Answers (1)

Nik Terentyev
Nik Terentyev

Reputation: 2310

Use : draggable plugin

To make an element draggable

var draw = SVG('canvas').size(400, 400)
var el = draw.rect(100, 100)

el.draggable()

There are four different callbacks available, beforedrag, dragstart, dragmove and dragend. This is how you assign them:

E.g. in your case:

el.dragstart = function() {
  this.remove();
}

or

el.dragsend = function() {
  this.remove();
}

or

el.dragsmove = function() {
  this.remove();
}

Upvotes: 2

Related Questions