How to get fabric.js canvas mouse cordinates on mozzila

空扰寡人 提交于 2019-12-11 03:25:34

问题


This is the code that is working on google chrome

var pointer = canvas.getPointer(event.e);
var posiX = pointer.x;  
var posiY = pointer.y;  
posiX=Math.round( posiX );
posiY=Math.round( posiY );

On mozzila i am getting "TypeError: event is undefined" and it is pointing at var pointer = canvas.getPointer(event.e);


回答1:


Dime,

Please use mouse events like this:

canvas.on('mouse:down', function(event){
   var pointer = canvas.getPointer(event.e);
   var posiX = pointer.x;  
   var posiY = pointer.y;  
   posiX=Math.round( posiX );
   posiY=Math.round( posiY );
});

'event' has to be defined as part of the function parameter. Please make sure you have the same logic.



来源:https://stackoverflow.com/questions/41636200/how-to-get-fabric-js-canvas-mouse-cordinates-on-mozzila

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