本文介绍了如何在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);
}

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

推荐答案

这可能是您的getMouse函数:

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

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

This is a unpdated working fiddle.http://jsfiddle.net/wv9MU/22/

这篇关于如何在fabric.js中显示鼠标坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 21:52