You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To make an element draggable just call `draggable()` on the element
30
30
31
31
```javascript
32
-
var draw =SVG()
33
-
.addTo('#canvas')
34
-
.size(400, 400)
32
+
var draw =SVG().addTo('#canvas').size(400, 400)
35
33
var rect =draw.rect(100, 100)
36
34
37
35
rect.draggable()
@@ -63,7 +61,7 @@ rect.off('dragstart.namespace')
63
61
64
62
### event.detail
65
63
66
-
`beforedrag`, `dragstart`, `dragmove` and `dragend` gives you the mouse / touch `event` and the `handler` which calculates the drag.
64
+
`beforedrag`, `dragstart`, `dragmove` and `dragend` gives you the mouse / touch `event` and the `handler` which calculates the drag. The `dragmove` event also gives you the `dx` and `dy` values for your convenience.
67
65
Except for `beforedrag` the events also give you `detail.box` which holds the initial or new bbox of the element before or after the drag.
68
66
69
67
You can use this property to implement custom drag behavior as seen below.
@@ -76,13 +74,13 @@ You can prevent the default action of `beforedrag` and `dragmove` with a call to
76
74
The shape won't be dragged in this case. That is helpfull if you want to implement your own drag handling.
77
75
78
76
```javascript
79
-
rect.draggable().on('beforedrag', e=> {
77
+
rect.draggable().on('beforedrag', (e)=> {
80
78
e.preventDefault()
81
79
// no other events are bound
82
80
// drag was completely prevented
83
81
})
84
82
85
-
rect.draggable().on('dragmove', e=> {
83
+
rect.draggable().on('dragmove', (e)=> {
86
84
e.preventDefault()
87
85
e.detail.handler.move(100, 200)
88
86
// events are still bound e.g. dragend will fire anyway
@@ -97,7 +95,7 @@ rect.draggable().on('dragmove', e => {
97
95
// Some constraints (x, y, width, height)
98
96
constconstraints=newSVG.Box(100, 100, 400, 400)
99
97
100
-
rect.on('dragmove.namespace', e=> {
98
+
rect.on('dragmove.namespace', (e)=> {
101
99
const { handler, box } =e.detail
102
100
e.preventDefault()
103
101
@@ -129,7 +127,7 @@ rect.on('dragmove.namespace', e => {
0 commit comments