FabricJS:垂直对齐文本中心 [英] FabricJS: Vertical Align text center

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

问题描述

我正在使用fabricjs 1.5,并且无法将文本垂直对齐到行中间。
我正在使用此代码设置行高

I am using fabricjs 1.5 and I am stuck on aligning the text in the middle of the line vertically. I am using this code to set the line height

text.setProperty('lineHeight', $scope.lineHeight.current);

它更改画布上文本的行高,但文本始终保留在顶部。我希望它位于垂直中间。请帮忙。

It changes the line height of text on canvas but text always remains at the top. I want it to be in the vertically middle. Please help.

推荐答案

您需要使用Fabricjs的较新版本。 1.5太旧了。要进行对齐,请使用 fabric.Textbox textAlign 属性。

You need to use newer versions of fabricjs. 1.5 is too old. For alignment use fabric.Textbox textAlign property.

DEMO

DEMO

var canvas = new fabric.Canvas("canvas");
canvas.add(new fabric.Textbox('FabricJS is Awsome',{width:300,textAlign:'center'}));

canvas{
 border: 1px solid #000;
}

<script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="canvas" width=400 height=400></canvas>

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

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