繁体   English   中英

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

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

嗨,我正在尝试显示或捕获程序中的鼠标坐标。 在此程序中,您可以单击任何按钮,然后将出现相应的图像。 我也想在此显示鼠标坐标。

我尝试了以下代码,但是它不起作用。 请让我知道我要去哪里了。

   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);
}

小提琴是: http : //jsfiddle.net/wv9MU/9/

这可能是您的getMouse函数:

function getMouse(options) {
    p = canvas.getPointer(options.e);
    document.getElementById('mouse').value = '' + p.x.toFixed() + ', ' + p.y.toFixed(0);
}

这是一个未经修饰的工作小提琴。 http://jsfiddle.net/wv9MU/22/

暂无
暂无

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

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