分组 | Group
可添加子元素,宽高随子元素自动变化。
const group = new Group()
关键方法
add(child: UI): void
添加子元素。
addAt(child: UI, index: number): void
在指定位置添加子元素。
addBefore(child: UI, before: UI): void
在指定元素前面添加子元素。
addAfter(child: UI, after: UI): void
在指定元素后面添加子元素。
remove(child?: UI): void
移除指定的子元素。
当 child 参数不存在时,移除当前元素。
遮罩方法
setMask(mask: IUI | IGroup): void
设置遮罩,支持 Group,默认添加到组内最底层
import { Leafer, Group, Rect, Ellipse } from 'leafer-ui'
const leafer = new Leafer({ view: window })
const group = new Group({ x: 100, y: 100, draggable: true })
leafer.add(group)
const rect = new Rect({ width: 200, height: 200, fill: '#32cd79' })
group.add(rect)
const mask = new Ellipse({
width: 100,
height: 100,
fill: 'black',
opacity: 0.5,
})
group.setMask(mask)
getMask(): void
获取遮罩
removeMask(mask?: IUI): void
移除遮罩