Run any animation or behavior (like wiggle or anything else) between two specific times inside After Effects.
var startTime = 2;
var stopTime = 5;
var t = time;
if (t >= startTime && t <= stopTime) {
wiggle(5,50);
} else {
value;
}
You can apply this expression to any property with a stopwatch (like Position, Rotation, Scale, Opacity, or any effect property).
// Set the time (in seconds) when you want the behavior to start
var startTime = 2;
// Set the time (in seconds) when you want the behavior to stop
var stopTime = 5;
// Get the current time
var t = time;
// Check if the current time is between startTime and stopTime
if (t >= startTime && t <= stopTime) {
// During the active time, you can apply any logic here
// Example: Wiggle Position 5 times per second with 50px amount
wiggle(5,50);
} else {
// Outside the active time, keep the property at its keyframed value
value;
}
First, you define when the effect should kick in (startTime
) and when it should stop (stopTime
). You’re setting these in seconds, so make sure you know your timeline.
Then, you grab the current time by using time
and store it in t
, just to keep it tidy.
Now, the expression checks: is the current time between the start and stop?
If yes, it runs the active logic. Right now, I’ve put a wiggle(5,50);
there so you can actually see it happening.
Important note: You can replace that wiggle with anything else you want later (maybe a loop, a bounce, some math... it's totally up to you).
If not (before startTime or after stopTime), it just uses the normal property value (value;
) and doesn’t apply any extra motion or effects.
So this whole setup basically gives you a window where you can turn any animation on or off based on time, super flexible!
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.
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.
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.
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.
Yes, you can use it on any property with a stopwatch. That includes Position, Scale, Opacity, and also effect settings like Blur or Tint.
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.
Explore more expressions in this category
Creates a smooth pulse that fades opacity between a minimum and maximum value you set, so it never fully disappears unless you want it to.
Lock a property to a specific frame rate so it updates at a fixed interval, perfect for stuttery or stop-motion effects.
A simple time-based expression that creates continuous motion or animation without keyframes.
Create a real-time digital clock in After Effects that updates every second using just an expression.