Fabric js text, vertical align to center

▼魔方 西西 提交于 2019-12-24 13:33:39

问题


I am using fabric.js library. I want to vertically align text to ceneter of textbox area. Please see image.

In image default cursor is align to top but i want it to center. Is there any property for text as valign like textalign?

Tried originY but no luck.


回答1:


fabric.js 3.5.1 works with originY: 'center'
see FabricJS: Vertical Align text center

.... but the bounding-box has no "minimum height" setting
and paddingX / paddingY are not supported by fabric

to solve this in fabric,
you must override the render function, as shown in
Draw border on Fabric Textbox when it's not selected

but it should be easier to use html elements,
and put them over your canvas, as shown in
How to put an html element over a fabric.js element



来源:https://stackoverflow.com/questions/49110454/fabric-js-text-vertical-align-to-center

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