问题
Hi I'm trying to display or capture the mouse coordinates in my program. In this program, you can click on any button and corresponding image will appear. I want to display the mouse coordinates on this too.
I tried the following code but it doesn't work. Please let me know where I am going wrong.
canvas.on('mouse:down', function(options){
getMouse(options);// its not an event its options of your canvas object
});
function getMouse(options) {
console.log(options);// you can check all options here
console.log(options.e.clientX);
}
The fiddle is: http://jsfiddle.net/wv9MU/9/
回答1:
This could be your getMouse function:
function getMouse(options) {
p = canvas.getPointer(options.e);
document.getElementById('mouse').value = '' + p.x.toFixed() + ', ' + p.y.toFixed(0);
}
This is a unpdated working fiddle. http://jsfiddle.net/wv9MU/22/
来源:https://stackoverflow.com/questions/22669974/how-can-i-display-the-mouse-coordinates-in-fabric-js