-
Notifications
You must be signed in to change notification settings - Fork 0
Drag Behavior
jasondavies edited this page Jul 25, 2012
·
12 revisions
Wiki ▸ API Reference ▸ Behaviors ▸ Drag Behavior
This behavior automatically creates event listeners to handle drag gestures on an element. Both mouse events and touch events are supported.
# d3.behavior.drag()
Constructs a new drag behavior.
# drag.on(type, listener)
Registers the specified listener to receive events of the specified type from the drag behavior. The following events are supported:
- "dragstart": fired when a drag gesture is started.
- "drag": fired when the element is dragged. d3.event will contain "x" and "y" properties representing the current absolute drag coordinates of the element. It will also contain "dx" and "dy" properties representing the element's coordinates relative to its position at the beginning of the gesture.
- "dragend": fired when the drag gesture has finished.
# drag.origin([origin])
If specified, sets the origin accessor function to the specified value. This function should return a two-element array specifying the starting coordinates of the element being dragged. If not specified, returns the current accessor function, which defaults to null.