Fabric JS文本,垂直居中对齐 [英] Fabric js text, vertical align to center

查看:855
本文介绍了Fabric JS文本,垂直居中对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用fabric.js库.我想将文本垂直对齐到文本框区域的中心.请看图片.

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

在图像中,默认光标是对齐顶部,但我希望它居中.像textalign这样的valign文本是否有属性?

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

尝试了originY,但是没有运气.

Tried originY but no luck.

推荐答案

fabric.js 3.5.1与originY: 'center'
一起使用 参见 FabricJS:垂直对齐文本中心

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

....,但是边界框没有最小高度"设置
面料不支持paddingX/paddingY

.... 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

,但是使用html元素应该更容易,
并将它们放在画布上,如
所示 如何将html元素放置在结构上. js元素

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

这篇关于Fabric JS文本,垂直居中对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆