Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make continuous animations for elements with shorter animation duration's [GASP]

I have the following GASP animation:

$(function () {
    var tmax_options = {
      repeat: -1
    };

    var tmax_tl = new TimelineMax(tmax_options),
      tween_options_to = {
        css: {
          rotation: 360,
          transformOrigin: 'center center'
        },
        ease: Cubic.Linear,
        force3D: true
    };

// Last Argument is Position Timing.
// Use this argument to stagger the visibility of surrounding circles
tmax_tl.to($('svg > path'), 10, tween_options_to, 0)
  .to($('svg > #XMLID_26_'), 5, tween_options_to, 0)
  .to($('svg > #XMLID_23_'), 70, tween_options_to, 0)
  .to($('svg > #XMLID_20_'), 65, tween_options_to, 0);
});

FIDDLE HERE

Now what I wanted to happen in the above animation is that the outermost polygons should rotate (they are found in total). All 4 should rotate at different speeds and should rotate continuously without stopping.

As of now my animation code looks like the following:

tmax_tl.to($('svg > path'), 10, tween_options_to, 0)
    .to($('svg > #XMLID_26_'), 5, tween_options_to, 0)
    .to($('svg > #XMLID_23_'), 70, tween_options_to, 0)
    .to($('svg > #XMLID_20_'), 65, tween_options_to, 0);

As you can see the duration are different: 10,5,70,65. Now the longest animation does't stop, but the shorter animations stop and and then start again at some point. How can I stop this? i.e., how do I make the animations such that the rotation for all the circles are the continuous without stopping?

like image 888
Alexander Solonik Avatar asked Apr 14 '16 19:04

Alexander Solonik


People also ask

What is the animation duration in CSS?

The animation-duration CSS property defines the length of time (in seconds or milliseconds) that an animation takes to complete one cycle of animation.

What is animation-duration in CSS?

The animation-duration CSS property sets the length of time that an animation takes to complete one cycle. It is often convenient to use the shorthand property animation to set all animation properties at once. The time that an animation takes to complete one cycle.

What is the default value of animation duration?

Default value for the animation-duration property is 0, which means that the animation starts immediately and the keyframes don’t have an effect. Negative values are invalid and they cause the property to be ignored. But they may be considered as equal to 0s by some earlier implementations.

What is the animation-duration Property?

The animation-duration property defines the length of time (in seconds or milliseconds) that an animation takes to complete its one cycle. Very often the animation shorthand property is used to set all animation properties at once.


1 Answers

The problem is that GSAP will only restart the loop if all animations in a TimelineMax object have stopped. Thus, you will need one TimelineMax object per gear:

$(() => {
    const tweenOptions = {
        css: {
            rotation: 360,
            transformOrigin: "center center"
        },
        ease: Linear.easeNone,
        force3D: true
    };
    const timelines = [];
    for (let i = 0; i < 4; ++i) {
        timelines.push(new TimelineMax({
            repeat: -1
        }));
    }
    timelines[0].to($("svg > path"), 10, tweenOptions, 0);
    timelines[1].to($("svg > #XMLID_26_"), 5, tweenOptions, 0)
    timelines[2].to($("svg > #XMLID_23_"), 70, tweenOptions, 0)
    timelines[3].to($("svg > #XMLID_20_"), 65, tweenOptions, 0);
});

Also, make sure to use Linear.easeNone if you want the speed of the animation to stay constant.

You can check out a demo here.

like image 145
Chiru Avatar answered Sep 20 '22 16:09

Chiru