getPointerPosition() of stage in React-Konva

前提是你 提交于 2019-12-11 21:53:59

问题


I would like to get cursor position on Stage in React-Konva by getPointerPosition() `handleStageOnMouseMove(e){ console.log(e.getPointerPosition()); }

render(){ return( {this.handleStageOnMouseOver(e)} } > Hello World ); } ` But I found some trouble that is when I move cursor over the program will return 's event instead of 's event.

** I have some method that is use 'ref' attribute to references but I don't know how to get cursor position.


回答1:


handleMouseMove = (e) => {
  // there are several ways to get stage reference

  // first is
  var stage = e.currentTarget;

  // or this:
  stage = this.stageRef.getStage();

  // or even this:
  stage = e.target.getStage();

  this.setState({
    cursor: stage.getPointerPosition()
  });
}

https://codesandbox.io/s/xp9o58nl2z



来源:https://stackoverflow.com/questions/50808980/getpointerposition-of-stage-in-react-konva

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