Loop

Automatically repeats your animation based on keyframes using built-in loop expressions. Great for cycles, continuous motion, or back-and-forth effects.

Author:
Denis Stefanides
Category:
Loop

Expression Code

loopOut()
// Repeats the animation after the last keyframe using the default loop type
js

Where to Apply

You can apply loop expressions to any property with a stopwatch (not just Position, Scale, or Rotation). It works on Opacity, Effects (like Blur), Masks, and more. If it has keyframes, it can loop.

How It Works

The loopOut() expression is the simplest form of a loop. It tells After Effects to repeat your animation after the last keyframe using the default loop type, which is "cycle."

If you’ve keyframed an animation (like bouncing a ball) and want it to repeat over and over after the last keyframe, just drop this in. No need to touch the timing.


Other Loop Variations

Let’s break down all the different types of loop expressions you can use in After Effects.


1. loopOut("cycle")

loopOut("cycle") // Loops the keyframed animation after the last keyframe in a cycle
js

Where to Apply

Any animated property: Position, Opacity, Scale, Effects, etc.

How It Works

This is the default loop type. Say you have 4 position keyframes that move an object up and down. When it gets to the last keyframe, it jumps back to the start and repeats the movement exactly the same way. There’s no blending. It just loops the same motion again and again.


2. loopOut("pingpong")

loopOut("pingpong") // Loops forward then reverses the animation after the last keyframe
js

Where to Apply

Any property with keyframes that you want to play forward, then backward, over and over.

How It Works

Perfect for seamless back-and-forth motion. Let’s say you keyframe an object moving from left to right. With "pingpong" it’ll go right, then left, then right again (without needing extra keyframes).


3. loopOut("offset")

loopOut("offset") // Loops the motion, but offsets the value so it keeps increasing or decreasing
js

Where to Apply

Usually used on properties like Position, Rotation, or Scale.

How It Works

This repeats your animation while adding the difference in value between loops.

So if an object moves 100px up between two keyframes, each loop adds another 100px. That creates a stair-step movement or endless scroll.


4. loopOut("continue")

loopOut("continue") // Keeps moving based on the velocity of the last keyframe
js

Where to Apply

Works great on linear motion properties like Position or Rotation.

How It Works

Instead of repeating or offsetting keyframes, this tells After Effects to keep going in the same direction and speed after the last keyframe. It uses the movement trend to predict what should happen next.


5. loopIn("cycle")

loopIn("cycle") // Cycles the animation before the first keyframe
js

Where to Apply

Useful when your animation needs to look like it started before the comp's timeline.

How It Works

Instead of looping after the animation, this loops the motion before your first keyframe.

Say your animation starts at frame 30, but you want it to feel like it was always moving before that. This is what you use.


6. loopOut("cycle", 2)

loopOut("cycle", 2) // Loops only the last 2 keyframes in a cycle
js

Where to Apply

Same as the rest (works on any keyframed property).

How It Works

The second number controls how many keyframes to include in the loop. In this example, After Effects will only loop the last two keyframes, ignoring any setup or earlier animation.

Frequently asked questions

How do I use the expression on this page?

Just copy the full expression code from the top of this page. Then Alt-click (or Option-click on Mac) the stopwatch on the property you want to animate. Paste the code into the editor and that's it. If you’re not sure which property to use, check the "Where to Apply" section above.

The expression isn’t working. What should I check?

First, make sure your project is using the JavaScript engine (go to File > Project Settings > Expressions). Also double-check for missing characters, and see if the code requires parenting a layer. If so, there will be a comment in the code explaining what needs to be connected.

I’m not sure what the expression does. Where can I learn more?

Take a look at the "How It Works" section on this page. It explains each part of the expression in plain language so you can understand how everything works together.

Can I customize how the expression behaves?

Yes, absolutely. Most expressions include easy-to-edit variables near the top and comments that guide you on what to change. You can also link sliders or checkboxes using Expression Controls if you want more control in the timeline.

Can I apply this to other properties too?

Yes, you can use it on any property with a stopwatch. That includes Position, Scale, Opacity, and also effect settings like Blur or Tint.

Will it work in comps with different frame rates or sizes?

In most cases, yes. These expressions are designed to adapt to your comp’s resolution and frame rate. If anything specific needs adjusting, it’ll be noted in the code or in the "How It Works" section.