我尝试了下面的代码片段,但是我在警告中未定义我在哪里访问此Coords.t1,有人可以指导我吗?
<!--fabric js function to get coordinates of active object-->
function getCoords(oCoords) {
return {
tl: new fabric.Point(oCoords.tl.x, oCoords.tl.y),
tr: new fabric.Point(oCoords.tr.x, oCoords.tr.y),
bl: new fabric.Point(oCoords.bl.x, oCoords.bl.y),
br: new fabric.Point(oCoords.br.x, oCoords.br.y)
}
}
<!--fabric js mouse move event-->
canvas.on('mouse:move', function(e){
console.log('over1',e.target)
if(e.target && e.target !== canvas.getActiveObject())
canvas.setActiveObject(e.target)
var thisCoords = getCoords(canvas.getActiveObject().oCoords);
alert("coords :"+thisCoords.t1);
});
答案 0 :(得分:0)
getCoords
函数返回一个带有键tl, tr, bl, br
的对象。您正在尝试访问密钥t1
,这肯定是一个错字。只需将alert("coords :"+thisCoords.t1);
替换为alert("coords :"+thisCoords.tl);