简体   繁体   English

GSAP staggerFrom 负延迟

[英]GSAP staggerFrom negative delay

Question:题:

I am wondering if there is a way to add a negative delay to the staggerFrom / staggerTo functions in greensock?我想知道是否有办法为 greensock 中的staggerFrom / staggerTo函数添加负延迟?

Problem:问题:

I have animation is running too long for my liking.我的动画运行时间太长,我不喜欢。 It would be great if my staggered animations could happen as the previous animations are playing to cut down the duration.如果我的交错动画可以发生,因为之前的动画正在播放以减少持续时间,那就太好了。

Example:例子:

I have put together this codepen to illustrate what I am after: http://codepen.io/nickspiel/pen/LpepvQ?editors=001我把这个代码笔放在一起来说明我的追求: http ://codepen.io/nickspiel/pen/LpepvQ?editors=001

You can see in the codepen that I have used negative delays on the basic from timeline functions but this doesn't work for the staggerForm function as the delay parameter is used to delay each element of the jquery collection.您可以在 codepen 中看到,我在基本from时间轴函数上使用了负延迟,但这不适用于staggerForm函数,因为延迟参数用于延迟 jquery 集合的每个元素。

Have you tried to use the new cycle property introduced in the latest v1.18.0 of GSAP?您是否尝试过使用 GSAP 最新v1.18.0中引入的新cycle属性?

So you can cycle with delay but passing 0 as stagger value in the staggerTo calls.因此,您可以delay循环,但在staggerTo调用staggerTo 0作为stagger值传递。

Also, you can pass position parameter to staggerTo calls to make them overlap with the previously inserted tween.此外,您可以将position参数传递给staggerTo调用,使它们与之前插入的补间重叠。

Here is the forked pen for an idea.是一个想法的分叉笔。

JavaScript: JavaScript:

...
animateElement = function() {
        timeline.from(main, 0.3, { scaleY: '0%', ease: Back.easeOut.config(1.7) })
        .staggerFrom(dataBlocks, 0.3, { cycle: { delay: function(index) {
            return index * 0.1;
        }}, scale: '0%', y: 100, ease: Back.easeOut.config(1.7) }, 0)
        .from(lineGraphLines, 1.5, { drawSVG: 0, ease: Power1.easeOut }, '-=0.5')
        .from(lineGraphAreas, 1, { opacity: 0, ease: Back.easeOut.config(1.7) }, '-=2.0')
        .staggerFrom(lineGraphDots, 0.2, { cycle: { delay: function(index) {
            return index * 0.1;
        }}, scale: 0, ease: Back.easeOut.config(1.7) }, 0, '-=1.0')
        .staggerFrom(donutCharts, 0.6, { cycle: { delay: function(index) {
            return index * 0.1;
        }}, drawSVG: 0, ease: Power1.easeOut }, 0, '-=2.0')
        .from(menuBackground, 0.3, { scaleX: '0%', ease: Back.easeOut.config(1.7) }, '-=6')
        .staggerFrom(menuElements, 0.3, { cycle: { delay: function(index) {
            return index * 0.1;
        }}, scaleX: '0%', ease: Back.easeOut.config(1.7) }, 0, '-=1')
        .from(headerBackground, 0.5, { scaleX: '0%', ease: Power1.easeOut }, '-=5.5')
        .staggerFrom(headerBoxes, 0.3, { cycle: { delay: function(index) {
            return index * 0.1;
        }}, scale: '0%', ease: Back.easeOut.config(1.7) }, 0, '-=1.0')
        .staggerFrom(headerText, 0.4, { cycle: { delay: function(index) {
            return index * 0.1;
        }}, scaleX: '0%', ease: Back.easeOut.config(1.7) }, 0, '-=1.0')
        .from(headerText, 0.4, { scaleX: '0%', ease: Back.easeOut.config(1.7) }, '-=4');
    };
...

This may not be exactly the type of animation you wanted but you'll need to adjust the position parameter in most/all of your tweens as per your liking but I think the main take away for you would be the use of cycle with delay .这可能不是您想要的动画类型,但您需要根据自己的喜好调整大多数/所有补间中的position参数,但我认为对您来说主要的收获是使用cycle with delay

Hope this helps in some way.希望这在某种程度上有所帮助。

PS You can pass negative stagger values but they have a different meaning. PS 您可以传递负的stagger值,但它们具有不同的含义。 It tells the engine to start the staggered animation from the last element.它告诉引擎从最后一个元素开始交错动画。

I asked this same question on the Greensock GitHub repo and had the following response:我在Greensock GitHub repo上问了同样的问题,得到了以下答复:

Absolutely - that's already baked in. I'm not sure if you're using TweenMax or one of the timeline classes, so I'll show you both:绝对 - 这已经完成了。我不确定您是使用 TweenMax 还是时间轴类之一,所以我将向您展示两者:

TweenMax.staggerTo(elements, 1, {x:100, delay:2}, 0.01);

// - OR -

var tl = new TimelineLite();
tl.staggerTo(elements, 1, {x:100, delay:2}, 0.01);

// - OR -

var tl = new TimelineLite(); 
tl.staggerTo(elements, 1, {x:100}, 0.01, "label+=3");

In my case the last option worked flawlessly.在我的情况下,最后一个选项完美无缺。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM