How can I display the mouse coordinates in fabric.js

房东的猫 提交于 2019-12-11 23:35:28

问题


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

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