Skip to content

定位

关键方法

seek ( time: number | IPercentData )

定位跳转到指定时间,支持设置具体时间(以秒为单位),或百分比(相对 duration 总时长)。

归属

Animate 类

示例

使用秒数定位跳转

ts
// #动画 - 通过 seek() 方法定位跳转动画 [数值(秒数)]
import { Leafer, Rect } from 'leafer-ui'
import { Animate } 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,
        autoplay: false // 不自动播放 //
    } // options
)

// 通过 seek() 方法定位跳转动画 //
setTimeout(() => {

    animate.seek(0.5)

}, 1000)

使用百分比定位跳转

ts
// #动画 - 通过 seek() 方法定位跳转动画 [百分比]
import { Leafer, Rect } from 'leafer-ui'
import { Animate } 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,
        autoplay: false // 不自动播放 //
    } // options
)

// 通过 seek() 方法定位跳转动画 //
setTimeout(() => {

    animate.seek({ type: 'percent', value: 0.25 }) // = 2 * 0.25

}, 1000)

Released under the MIT License.