Unlock nodes on grab/mousedown event, can not move them immediately in Cytoscape.js

时间秒杀一切 提交于 2020-01-05 11:03:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!