position
元素的坐标定位属性,相对父元素进行绝对定位。
关键属性
x: number
x 轴位置。
y: number
y 轴位置。
关键方法
move ( addX: number | IPointData, addY = 0, transition?: ITranstion)
位移元素 增量操作, 支持直接传入 坐标对象。
transition 参数表示是否进行 动画 过渡。
ts
// 沿 X/Y 轴同时移动 10 像素
rect.move(10, 10)
// 使用 point 沿 X/Y 轴同时移动 10 像素
rect.move({ x: 10, y: 10 })
// 动画过渡移动
rect.move(10, 10, true)
rect.move(10, 10, 2) // 过渡 2 秒moveInner ( addX: number | IPointData, addY = 0, transition?: ITranstion)
在 内部坐标系 中位移元素 增量操作, 支持直接传入 坐标对象。
moveWorld ( addWorldX: number | IPointData, addWorldY = 0, transition?: ITranstion)
在 世界坐标系 中位移元素 增量操作, 支持直接传入 坐标对象。
归属
UI 元素
示例
通过 move() 移动元素
ts
ts
// #通过 move() 移动元素 [无动画过渡 (App)]
import { App, Rect } from 'leafer-ui'
import '@leafer-in/editor' // 导入图形编辑器插件
import '@leafer-in/viewport' // 导入视口插件 (可选)
const app = new App({ view: window, editor: {} })
const rect = Rect.one({ fill: '#32cd79' })
app.tree.add(rect)
setTimeout(() => {
// 沿 X/Y 轴同时移动 100 像素
rect.move(100, 100)
}, 1000)通过 move() 移动元素,有动画过渡
ts
ts
// #通过 move() 移动元素 [有动画过渡 (App)]
import { App, Rect } from 'leafer-ui'
import '@leafer-in/editor' // 导入图形编辑器插件
import '@leafer-in/viewport' // 导入视口插件 (可选)
import '@leafer-in/animate' // 导入动画插件 //
const app = new App({ view: window, editor: {} })
const rect = Rect.one({ fill: '#32cd79' })
app.tree.add(rect)
setTimeout(() => {
// 沿 X/Y 轴同时移动 100 像素
rect.move(100, 100, true)
}, 1000)