前端前端
fabric
算法
jsBlock
styleBlock
svgBlock
工具其他
Vue、React相关
webgl
GitHub
fabric
算法
jsBlock
styleBlock
svgBlock
工具其他
Vue、React相关
webgl
GitHub
  • 元素操作

    • 元素分组
    • 元素定位
    • 元素层级
    • 元素禁止事件
    • 元素选中样式
  • 变换

    • 变换
  • 图片

    • 图片
    • 背景图
  • 基础图形

    • 三角形
    • 圆形
    • 多边形
    • 折线
    • 椭圆
    • 直线
    • 矩形
    • 路径
  • 序列化和反序列化

    • 反序列化
    • 输出JSON
    • 输出png
    • 输出svg
  • 文本

    • 可编辑文本
    • 多行文本
    • 文本
    • 文本省略
    • 文本边框
  • 源码

    • fabric.Canvas
    • fabric.Circle
    • fabric类的继承体系
  • 画布操作

    • 画布拖动和缩放
    • 画布框选样式
  • 示例

    • fabric-echarts-demo
    • 拓扑图一
    • 拓扑图二

多行文本

创建

使用 new fabric.Textbox(string, object) 方法创建多行文本

当设置好元素宽度后,文本内容会根据单词换行。但是中文不换行,可以设置居中

show code

const text = new fabric.Textbox('Please translate this sentence for me', {
  fill: '#f00',
  stroke: 'blue',
  strokeWidth: 2,
  width: 300,
})

show code

const text = new fabric.Textbox('点击可编辑,但是不换行不换行不换行不换行', {
  fill: '#f00',
  stroke: 'blue',
  strokeWidth: 2,
  width: 300,
})

show code

const text = new fabric.Textbox('我可以居中', {
  fill: '#f00',
  stroke: 'blue',
  strokeWidth: 2,
  textAlign: 'center',
  width: 300,
})
Edit this page
最近更新:: 2025/4/24 10:47
Contributors: wu.hui
Prev
可编辑文本
Next
文本