Javascript 如何在TimelineMax中获取当前动画序列的进度

Javascript 如何在TimelineMax中获取当前动画序列的进度,javascript,animation,gsap,Javascript,Animation,Gsap,我正在使用timelinemax执行一系列tweens,如下所示: this.backgroundColorTimeline = new TimelineMax({ repeat: -1, yoyo: true, onUpdate:this.updateTimeline, }); palette.bg.forEach((paletteColor) => { this.backgroundColorTimeline.add(TweenMax.to(this.

我正在使用timelinemax执行一系列tweens,如下所示:

this.backgroundColorTimeline = new TimelineMax({
    repeat: -1,
    yoyo: true,
    onUpdate:this.updateTimeline,
});

palette.bg.forEach((paletteColor) => {
    this.backgroundColorTimeline.add(TweenMax.to(this.bg, settings.colorAnimTime, {
        easel: { tint: paletteColor },
    }));
});
在每个TweenMax实例运行时,我希望能够获得其进度。因此,如果我的时间轴有10个tweenmax动画,我希望在更新时获得每个动画的进度(从0到1的比例)

我看到timelinemax有一个
progress
事件,但这不会将时间除以每个动画


如何获取当前动画的进度?

只需使用
onUpdate
回调来跟踪每个实例的进度:

ES5方式

function getProgress () {
    var currProgress = this.progress();
}
palette.bg.forEach((paletteColor) => {
    this.backgroundColorTimeline.add(TweenMax.to(this.bg, settings.colorAnimTime,{
        easel: { tint: paletteColor },
        onUpdate: getProgress
    }));
});
const getProgress = t {
    const currProgress = t.progress();
}
palette.bg.forEach((paletteColor) => {
    this.backgroundColorTimeline.add(TweenMax.to(this.bg, settings.colorAnimTime,{
        easel: { tint: paletteColor },
        onUpdate: getProgress, onUpdateParams: ["{self}"]
    }));
});

ES6+方式

function getProgress () {
    var currProgress = this.progress();
}
palette.bg.forEach((paletteColor) => {
    this.backgroundColorTimeline.add(TweenMax.to(this.bg, settings.colorAnimTime,{
        easel: { tint: paletteColor },
        onUpdate: getProgress
    }));
});
const getProgress = t {
    const currProgress = t.progress();
}
palette.bg.forEach((paletteColor) => {
    this.backgroundColorTimeline.add(TweenMax.to(this.bg, settings.colorAnimTime,{
        easel: { tint: paletteColor },
        onUpdate: getProgress, onUpdateParams: ["{self}"]
    }));
});

只需使用
onUpdate
回调来跟踪每个实例的进度:

ES5方式

function getProgress () {
    var currProgress = this.progress();
}
palette.bg.forEach((paletteColor) => {
    this.backgroundColorTimeline.add(TweenMax.to(this.bg, settings.colorAnimTime,{
        easel: { tint: paletteColor },
        onUpdate: getProgress
    }));
});
const getProgress = t {
    const currProgress = t.progress();
}
palette.bg.forEach((paletteColor) => {
    this.backgroundColorTimeline.add(TweenMax.to(this.bg, settings.colorAnimTime,{
        easel: { tint: paletteColor },
        onUpdate: getProgress, onUpdateParams: ["{self}"]
    }));
});

ES6+方式

function getProgress () {
    var currProgress = this.progress();
}
palette.bg.forEach((paletteColor) => {
    this.backgroundColorTimeline.add(TweenMax.to(this.bg, settings.colorAnimTime,{
        easel: { tint: paletteColor },
        onUpdate: getProgress
    }));
});
const getProgress = t {
    const currProgress = t.progress();
}
palette.bg.forEach((paletteColor) => {
    this.backgroundColorTimeline.add(TweenMax.to(this.bg, settings.colorAnimTime,{
        easel: { tint: paletteColor },
        onUpdate: getProgress, onUpdateParams: ["{self}"]
    }));
});