简体   繁体   English

如何在fabric.js中显示鼠标坐标

[英]How can I display the mouse coordinates in fabric.js

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/ 小提琴是: http : //jsfiddle.net/wv9MU/9/

This could be your getMouse function: 这可能是您的getMouse函数:

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/ http://jsfiddle.net/wv9MU/22/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM