4

I'm looking for an event that fires as a node is being dragged. I thought that tapdrag looked like what I wanted, but tapdrag fires whenever the mouse moves over the node only when the mouse button is not down (so the node's not being dragged, basically mouseover). I've tried several other events, but none seem to do what I need.

How can I fire an event as a node is being dragged? Specifically, I want to move another node while the first is being dragged, which I'd rather do without using a compound node.

TonyM
  • 245
  • 3
  • 10

1 Answers1

6

Use the drag event.

The events are all listed and documented: http://js.cytoscape.org/#events/collection-events

You can manually .position() on the second node when the drag happens on the first node.

To set rules for node placement, like moving two nodes in lockstep, use the automove extension: https://github.com/cytoscape/cytoscape.js-automove

maxkfranz
  • 11,896
  • 1
  • 27
  • 36
  • Thanks! This is just what I was looking for. – TonyM Nov 30 '15 at 23:32
  • @maxkfranz, I'm trying to do the same - move another node while the first is being dragged without using compound nodes. Inside the drag event on a regular node, I've tried `cy.nodes('myselector').trigger('drag')`, but it only selects the node I want to add to the drag collection, without moving it. How can I programmatically make it move along with the node I want? – ForOhFor Jan 12 '17 at 10:07
  • @ForOhFor Triggering an event doesn't move a node. You either have to `.position()` the other node yourself or use something more automated like the automove extension: https://github.com/cytoscape/cytoscape.js-automove – maxkfranz Jan 14 '17 at 03:03