Start/End Expression at Specific Time

Run any animation or behavior (like wiggle or anything else) between two specific times inside After Effects.

Author:
Denis Stefanides
Category:
Time

Expression Code

var startTime = 2;
var stopTime = 5;
var t = time;

if (t >= startTime && t <= stopTime) {
  wiggle(5,50);
} else {
  value;
}
javascript

Where to Apply

You can apply this expression to any property with a stopwatch (like Position, Rotation, Scale, Opacity, or any effect property).


How It Works

// 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;
}
javascript
  • 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!

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.

Related Expressions

Explore more expressions in this category