简体   繁体   English

fabric.js对象选择鼠标按下

[英]fabric.js object selection mouse down

I want to know if there is a way to select correct object when we click on it to change the color. 我想知道当我们点击它来改变颜色时是否有办法选择正确的对象。

I have two angular triangles on my canvas but when i click on it i can only select one because the bounding box is squared. 我的画布上有两个角三角形但是当我点击它时我只能选择一个,因为边界框是平方的。

I use : 我用 :

canvas.on('mouse:down', function(e)) 

But i am unable to select the triangle i want only 1 is selectable due to the size of bounding box. 但由于边界框的大小,我无法选择我想要的只有1可选的三角形。

Thank you for your help 谢谢您的帮助

I want to change the color of the triangle when i click on it. 我想点击它时改变三角形的颜色。 Example if i click on the red triangle this triangle come green. 例如,如果我点击红色三角形,此三角形变为绿色。 If i click on the black triangle this one comes blue. 如果我点击黑色三角形,那么它会变成蓝色。 But its impossible at this time. 但此时此刻不可能。

You can try something like this: 你可以尝试这样的事情:

canvas.on('mouse:down', function(e){
var triangle = e.target;
if(triangle)
triangle.setFill('your color');
}); 

You can add 你可以加

perPixelTargetFind: true // prevents clicking on bounding-box around shape from selecting it

to the triangles 到三角形

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

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