AnimateEvent
Animation event
Event Names
AnimateEvent.CREATED
Animation instance created event.
created
AnimateEvent.PLAY
Play animation event.
play
AnimateEvent.PAUSE
Pause animation event.
pause
AnimateEvent.STOP
Stop animation event.
stop
AnimateEvent.SEEK
Seek animation event.
seek
AnimateEvent.UPDATE
Update animation event. Triggered on every style change.
update
AnimateEvent.COMPLETED
Animation completed event.
completed
Example
Supports listening and removing events like elements, and also supports passing event listener object during initialization.
ts
// #动画 - 通过 on() 监听动画事件 [event(Animate)]
import { Leafer, Rect } from 'leafer-ui'
import { Animate, AnimateEvent } from '@leafer-in/animate' // 导入动画插件
const leafer = new Leafer({ view: window })
const rect = Rect.one({ fill: '#32cd79' }, 0, 100, 50, 50)
leafer.add(rect)
const animate = new Animate(
rect,
{ x: 500 }, // style keyframe
{ duration: 2 } // options
)
// 监听动画事件
animate.on(AnimateEvent.PLAY, () => { // 动画创建
console.log('play')
})
animate.on(AnimateEvent.UPDATE, (animate: Animate) => { // 更新中...
console.log(animate.style.x)
})
animate.on(AnimateEvent.COMPLETED, () => { // 动画已完成
console.log('completed')
})ts
// #动画 - 通过 on() 监听动画事件 [event(animate)]
import { Leafer, Rect } from 'leafer-ui'
import { Animate, AnimateEvent } from '@leafer-in/animate' // 导入动画插件
const leafer = new Leafer({ view: window })
const rect = Rect.one({ fill: '#32cd79' }, 0, 100, 50, 50)
leafer.add(rect)
const animate = rect.animate(
{ x: 500 }, // style keyframe
{ duration: 2 } // options
)
// 监听动画事件
animate.on(AnimateEvent.PLAY, () => { // 动画创建
console.log('play')
})
animate.on(AnimateEvent.UPDATE, (animate: Animate) => { // 更新中...
console.log(animate.style.x)
})
animate.on(AnimateEvent.COMPLETED, () => { // 动画已完成
console.log('completed')
})