问题描述
我想知道是否有一个简单的方法来添加一个删除,带到前面,带回到
函数到现有的 fabric.js 对象控件。
I would like to know if there is an easy way to add a delete, bring to front, bring to backfunction into the existing fabric.js object controls.
此刻,我只能点击将删除对象,带到前面等的按钮。
At the moment I can only click on buttons which would delete object, bring to front etc.
找到一个解决方案,能够按下对象上的X(在右上角)并删除对象。
I am working on finding a solution to be able to press X (on the upper right corner) on the object and delete the object.
与覆盖,包装或子类化现有的控制对象有关。
I guess it will have to do with overwriting, wrapping or subclassing the existing control object.
也许我有监督的东西,有一个容易的解决方案?请勿使用Div Wrapper。
Maybe I have overseen something and there is an easy solution? Please no Div Wrapper.
推荐答案
Fabric.js不提供任何简单的对对象添加控件的方法。
如果你想创建自己的控件,你必须覆盖Object类,特别是:
Fabric.js does not offer any simple mean of adding controls to objects.If you want to create your own controls, you will have to overwrite the Object class, notably:
- override
drawControls
,要绘制您的自定义按钮 - ,您需要存储按钮的坐标,以便您可以检测用户何时点击它们。 C.f.
_setCornerCoords
和_findTargetCorner
- 将您的操作纳入
__ onMouseDown
- override
drawControls
, to draw your custom button - you will need to store the button's coordinates, so that you can detect when the user clicks them. C.f.
_setCornerCoords
and_findTargetCorner
- incorporate your action somewhere in
__onMouseDown
您不需要照顾
我希望这有助于,祝你好运:)
I hope this helps, and good luck :)
这篇关于向控件添加自定义删除(后,toFront)按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!