问题
At first all my nodes are locked. I would like to unlock all of them on drag event. I tried the following solution with no success:
cy.nodes().on('grab', function() {
cy.nodes().unlock();
});
I realized that 'grab' event does not occur on locked nodes, so I changed it to 'mousedown' instead. Now if I click on a node and hold it, every node unlocks as expected, but I can not move immediately the node I clicked, I have to release the button then drag the node again. Is there a solution to this problem? Thanks!
回答1:
You should not depend on undocumented behaviour for when locked checks happen. Consider that when the checks happen might change from version to version. Consider touch device support.
Instead, you should lock nodes only when they need to be locked. If you want nodes to be grabbable, then they should not be locked by default. You should use locking only when necessary, perhaps during layout, and unlock immediately afterwards.
来源:https://stackoverflow.com/questions/33365115/unlock-nodes-on-grab-mousedown-event-can-not-move-them-immediately-in-cytoscape