Skip to content

Commit 94447de

Browse files
committed
feat: pass dx and dy to dragmove event details
1 parent 008fba0 commit 94447de

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ import '@svgdotjs/svg.draggable.js'
2929
To make an element draggable just call `draggable()` on the element
3030

3131
```javascript
32-
var draw = SVG()
33-
.addTo('#canvas')
34-
.size(400, 400)
32+
var draw = SVG().addTo('#canvas').size(400, 400)
3533
var rect = draw.rect(100, 100)
3634

3735
rect.draggable()
@@ -63,7 +61,7 @@ rect.off('dragstart.namespace')
6361

6462
### event.detail
6563

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.
6765
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.
6866

6967
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
7674
The shape won't be dragged in this case. That is helpfull if you want to implement your own drag handling.
7775

7876
```javascript
79-
rect.draggable().on('beforedrag', e => {
77+
rect.draggable().on('beforedrag', (e) => {
8078
e.preventDefault()
8179
// no other events are bound
8280
// drag was completely prevented
8381
})
8482

85-
rect.draggable().on('dragmove', e => {
83+
rect.draggable().on('dragmove', (e) => {
8684
e.preventDefault()
8785
e.detail.handler.move(100, 200)
8886
// events are still bound e.g. dragend will fire anyway
@@ -97,7 +95,7 @@ rect.draggable().on('dragmove', e => {
9795
// Some constraints (x, y, width, height)
9896
const constraints = new SVG.Box(100, 100, 400, 400)
9997

100-
rect.on('dragmove.namespace', e => {
98+
rect.on('dragmove.namespace', (e) => {
10199
const { handler, box } = e.detail
102100
e.preventDefault()
103101

@@ -129,7 +127,7 @@ rect.on('dragmove.namespace', e => {
129127
#### Snap to grid
130128

131129
```js
132-
rect.on('dragmove.namespace', e => {
130+
rect.on('dragmove.namespace', (e) => {
133131
const { handler, box } = e.detail
134132
e.preventDefault()
135133

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@svgdotjs/svg.draggable.js",
3-
"version": "3.0.5",
3+
"version": "3.0.6",
44
"description": "An extension for svg.js which allows to drag elements with your mouse",
55
"type": "module",
66
"main": "dist/svg.draggable.js",

src/svg.draggable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class DragHandler {
9090
event: ev,
9191
handler: this,
9292
box: this.box,
93+
dx,
94+
dy,
9395
}).defaultPrevented
9496
) {
9597
return

0 commit comments

Comments
 (0)