问题
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