Skip to content

使用

初始化

ts
const rubbing = new Rubbing({
  // ...options
})

// 请在 canvas 实际存在时调用
await rubbing.init()

渲染

ts
rubbing.loadFrom({
  objects: [
    // ...shapes here
  ],
})

示例

Source Code
js
const rubbing = new Rubbing({
  selector: '#canvas',
  background: '#fff',
  width: 300,
  height: 100,
})
await rubbing.init()
rubbing.loadFrom({
  objects: [
    {
      type: 'text',
      text: '🎉 Rubbing!',
      left: 0,
      top: 50,
      fontSize: 16,
      fill: '#7c3aed',
      width: 300,
      textAlign: 'center',
    },
  ],
})

Options

PropertyDescriptionTypeRequiredDefault
selectorcanvas 选择器stringtrue-
widthcanvas 宽度numbertrue0
heightcanvas 高度numbertrue0
radius圆角半径numberfalse0
backgroundcanvas 背景色stringfalsetransparent
component小程序组件中使用需传 thisComponent.Instancefalse-

Methods

MethodDescriptionParametersReturn
init初始化-Promise<{ canvas: CanvasElement, context: CanvasRenderingContext2D }>
loadFrom加载图形{ objects: ShapeObject[] }Promise<void>

图形对象

ShapeObject