Ae

Dynamic Timeline Slider (Loki Disney+)

Intermediate

I’ve been loving the visual elements in the new Loki series on Disney+ and it inspired me to recreate some of the visuals in After Effects.

In this video we look at creating the timeline slider used to display changes in what year a scene is taking place in. We rig the whole thing with expressions to enable us to dynamically control the animation, and take things one step further by adding in the ability to not only do years, but full dates as well.

Stay tuned for more tutorials breaking down other visual elements from the Loki series.

Also yes I’m slowly coming back after the birth of my twins. They’re amazing boys but they take up all my time so it’s hard to find a spare couple days to sit down to create a video. But I haven’t forgotten you all and will be attempting to do more videos in the future.


New Composition and creating matte layer

As usual we will start off in a brand new composition, we will call it “Final“.

Next we will create a new solid (Layer -> New -> Solid) and make it the comp size, calling it “Matte” as it will be our matte layer.

Selecting the solid we are going to draw out a mask on it. Select the Rectangle tool and click in the centre of the solid, holding Ctrl so it scales from the centre and dragging it out so it is the whole height of our composition and about 50% the width of our composition. It leaves about 25% on the left and right that are outside of the mask.

Pressing (F) will bring up the Mask Feather in our timeline. Uncheck the chain (Constrain Proportions) and then drag the first value so it feathers the two visible sides (I feathered to 350px).

Having created our matte we now want to pre-compose this. Selecting the layer right+click and select Pre-Compose and we will “Move all attributes”. Call the new composition “Matte“.

At the bottom of the composition window we can toggle on Title/Action Safe so that we have some guides to work with.

Return to the “Final” Composition.

Creating Shape Elements

Using the Pen tool (G) with no layers selected, we will use our guides to click two points to draw a line horizontally in the centre of our composition from the left to the right sides of the screen.

At the top toolbar we can uncheck the fill, change the stroke colour to white and then set the stroke width to 3px.

Rename the line layer to “Line”. Go to Effect -> Channel -> Set Matte to apply the Set Matte effect to the line layer. Toggle the “Take Matte From Layer” to our Matte layer.

Next is the circle element. We will go to where the rectangle tool is and select the Ellipse Tool (Q). Clicking in the centre we can use ctrl and shift to scale evenly from the centre. Switch the stroke off and the fill to solid white.

Looking down in the timeline we want to toggle the contents until we see Ellipse 1. Selecting it and selecting Ctrl + D will duplicate that element within the shape layer. We can now manipulate our old Ellipse element (Ellipse 1) by toggling the path and scaling the Size property down.

We also want to add a Rectangle to this same shape layer. Keeping the layer selected and then selecting the rectangle tool will let us drag out a rectangle so it is not very tall but so that the left and right sides overhang both ellipses.

Looking in the timeline panel, drag the rectangle element down underneath the other two ellipses. Next we add another element by clicking Add and selecting “Merge Paths” from the menu.

Toggling Merge Paths to see Mode, and then select Subtract. This will use the top Ellipse as the original shape, and then subtract the next two shapes from the first shape.

We want one more circle in the middle so selecting any of the Ellipses we use Ctrl+D to duplicate, and then drag it underneath the Merge Paths. Going into the new ellipse path we want to scale the size down slightly to make our final shape element complete.

We can use (S) to show the scale transform property for the whole layer, in order to scale it to a smaller size that suits our composition.

Rename the layer to “Dot“.

Adding in the Text Layer

Now we add in our actual date that will be shown. Grab the text tool and click above our dot in the centre. Type out any year you want to get us started. Scale the text to whatever size suits your composition, but position it directly in the centre of the screen, then offset slightly above the dot.

For my text I used the font Futura LT Condensed Bold and toggled on the All Caps option.

We now want to parent our Dot layer to our Text layer by toggling in the timeline to see the Parent option (toggle view with F4) and then use the pickwhip (swirl icon) to drag to parent the Dot layer to the text layer.

To apply our Matte to our Dot and Text layers we need to apply an effect for each layer. Selecting each, go to Effect -> Channel -> Set Matte and toggle “Take Matte From Layer” to be from our Matte layer.

 

 

Setting up Text Layer Expression Controls

Before adding any expressions we need to set up our text layer to have all the expression controls we need, mainly slider controls.

Selecting our Text Layer go to Effect -> Expression Controls -> Slider Control to add the first slider control. Hit Enter to rename to “Left“.

We want to then duplicate our Slider Control by pressing Ctrl + D, rename the new one to Center.

Duplicate again and rename to Right.

Duplicate again and rename to Start Value.

Duplicate again and rename to End Value.

Duplicate again and rename to Value Step.

Duplicate one last time and rename to Animation.

The first three slider values ( Left, Center, Right) reference the three positions our text layer will cycle through in our composition. Let us add them in now.

Selecting our text layer hit (P) to see our position property, looking at the first number for our position on the x axis.

That is our center value so enter that into the Center slider control.

Holding shift and dragging the text layer to the left we are looking for when our text layer fades out completely. Look at the position property value and enter it into the Left slider control.

Repeating again, drag the text layer to the right until it is faded out completely and add the position property value into the Right slider control.

To reset the text layer we can take our center value and type it into the position property we were looking at a moment earlier.

The Start Value and End Value are the year we first see, and the year we will transition to.

For now throw in to years. In the tutorial I use 2021 as my Start Value, and 1955 for the End Value.

The Value Step slider control defines how many dates appear between those two values as my animation plays out. For now let us set that value to 5.

Finally the Animation slider control is what we will use to control the entire animation sequence.

Now it is time to set some expressions. We will apply all our expressions to the text layer.

 

Code Snippet
Text Layer position
var step = 100 / effect("Value Step")("Slider");
var ref = (effect("Animation")("Slider") % step) / step;

if(ref > 0.5){
var res = linear
linear(x,xMin,xMax,yMin,yMax)

The Linear Expression interpolates values by calculating where “x” falls between “xMin” and “xMax” and then giving a result that is the value equivalently positioned between “yMin” and “yMax“.

(ref,0.5,1,effect("Left")("Slider"),effect("Center")("Slider"));
}else{
var res = linear
linear(x,xMin,xMax,yMin,yMax)

The Linear Expression interpolates values by calculating where “x” falls between “xMin” and “xMax” and then giving a result that is the value equivalently positioned between “yMin” and “yMax“.

(ref,0,0.5,effect("Center")("Slider"),effect("Right")("Slider"));
}
value = [res,transform.position[1]];
Code Snippet
Text Layer sourceText
var step = 100 / effect("Value Step")("Slider");
var ref = Math.floor
Math.floor(value)

A classic Math expression that takes a decimal number value and rounds it down to nearest whole number. e.g. 1.45 would round down to 1, and 2.9999 would round down to 2.

(effect("Animation")("Slider") / step);
var src = (effect("Animation")("Slider") % step) / step;

ref = src > 0.5 ? ref + 1 : ref;

value = Math.floor
Math.floor(value)

A classic Math expression that takes a decimal number value and rounds it down to nearest whole number. e.g. 1.45 would round down to 1, and 2.9999 would round down to 2.

(linear
linear(x,xMin,xMax,yMin,yMax)

The Linear Expression interpolates values by calculating where “x” falls between “xMin” and “xMax” and then giving a result that is the value equivalently positioned between “yMin” and “yMax“.

(ref,0,effect("Value Step")("Slider"),effect("Start Value")("Slider"),effect("End Value")("Slider")));
Animating

Now that we have set up our expressions you can see as we drag the Animation slider control between 0 and 100 that our text layer flicks through 5 times for each step we count, then finally landing on our End Value.

To animate we want to go forward in our timeline a few frames, then with our Animation Slider Control click the stopwatch to set a keyframe for the 0 value.

Go forward to give space for the animation to play, and then set a new keyframe by dragging the Animation Slider Control to have a value of 100.

We now want to ease our keyframes. Clicking U will show the Animation slider keyframes, then selecting the end keyframe press F9 to set easy ease. Use the graph editor to drag out the easing of that layer so that it slows down as it approaches the end of our animation.

To animate in our elements select the Dot layer and press (S) to show the scale property, and we will move our playhead to where our animation is just about to start then set a keyframe for the current scale. Move the playhead to the very start of the composition then type 0 in the scale property to make the dot layer completely hidden.

Animating the scale for the line I want to uncheck constrain proportions and then repeat the steps, going to where my animation is about to start and setting a keyframe, and then moving to the start and typing 0 in the first scale property to set 0 for the xAxis scale.

Toggling on the motion blur for all layers also adds to the movement of the animation.

To do a final animation lets add in a new Ellipse. Drag it out from the centre of the composition. Change the fill to empty and the stroke to white and set the stroke width to 3. Scale it all the way to 0 at the start of the composition timeline and set a keyframe. Move the timeline forward and then drag out the scale a whole heap.

Double tap (U) to show all the properties we have changed. Selecting the Stroke Width value, set a keyframe and then set another keyframe at the start of the composition timeline as well. About three quarters of the way between the two keyframes set a new keyframe and drag out the stroke width to make it quite fat.

Pressing (T) will bring up the Opacity property. Set a keyframe at the start of the composition timeline and set it to 0%. Go forward to line up with the other keyframes we have made and set the value to 0%. Then about half way through keyframe the opacity value to 80%.

Let us duplicate that new Ellipse layer then drag it forward in the timeline slightly and then toggle until we see the Ellipse Path size and scale it down slightly.

 

 

Adding actual dates rather than years

Taking it one step further we can make the text layer cycle between actual dates rather than simply years.

Selecting the text tool we will make some reference text layers. Click up the top left and type out a date. In my tutorial I use June 13, 2021. It needs to be an actual date format.

Ctrl + D to duplicate the layer and drag it to the right hand side. Change the date to an end date. I use the classic one from Back to the Future, November 5, 1955.

Rename the first date to Start Date.

Rename the second date to End Date.

Toggle those two layers off as we do not need to see them once we have set their values.

We now need to modify our sourceText expression for our Text Layer to reference these new values and format it correctly.

Code Snippet
Text Layer sourceText
var step = 100 / effect("Value Step")("Slider");
var ref = Math.floor
Math.floor(value)

A classic Math expression that takes a decimal number value and rounds it down to nearest whole number. e.g. 1.45 would round down to 1, and 2.9999 would round down to 2.

(effect("Animation")("Slider") / step);
var src = (effect("Animation")("Slider") % step) / step;

ref = src > 0.5 ? ref + 1 : ref;

var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var startDate = new Date(thisComp.layer("Start Date").text.sourceText);
var endDate = new Date(thisComp.layer("End Date").text.sourceText);

var datetime = Math.floor
Math.floor(value)

A classic Math expression that takes a decimal number value and rounds it down to nearest whole number. e.g. 1.45 would round down to 1, and 2.9999 would round down to 2.

(linear
linear(x,xMin,xMax,yMin,yMax)

The Linear Expression interpolates values by calculating where “x” falls between “xMin” and “xMax” and then giving a result that is the value equivalently positioned between “yMin” and “yMax“.

(ref,0,effect("Value Step")("Slider"),startDate.getTime(),endDate.getTime()));

var presented = new Date(datetime);
var fullyear = '' + presented.getFullYear();

value = presented.getDate() + ' ' + months[presented.getMonth()] + " '" + fullyear.substr(2,2);
Completed

That is how you add in showcasing full dates and can cycle through the animation as we would if it were just showing years.

See below for formatting the full date in different ways.

Alternative Date Formatting

Let’s talk formatting the date. In our expression we had the following piece of code.

var presented = new Date(datetime);

This creates a new Date object called presented. We can use this object to generate the different formatting options.

For example…

var fullyear = ” + presented.getFullYear();

This creates a new variable called fullyear. We need to first say it equals two single quotation marks at the start with nothing in between to tell our expression to start to treat this variable as a string. (Don’t know about variables and strings, watch my tutorial here) Then using + we can then add the result of a date function used on our presented variable to get a particular value.

The final line is where we define what value is actually set is. Value is a special variable in expressions as it represents the final value that the property is set with. So regardless of any code you write, if you define what value is, that is what that value will be unless you redefine it later in your expression.

value = presented.getDate() + ‘ ‘ + months[presented.getMonth()] + ” ‘” + fullyear.substr(2,2);

We have a few values getting added one after the other for our final value. First we are using the .getDate() function to return the day of the month. Secondly we use presented.getMonth() to get the current month, where 0 is the first month. Finally we use fullyear.substr(2,2) to select two digits, two digits in from the start of the value of fullyear.

If we want to customise our date formatting to be different we can use any of the following to create variables prior to setting what value equals, and then use + to add them on to our value result. Adding + ‘ ‘ + will also add a space between two values.

  • var dayofmonth = ” + presented.getDate();
    returns the day of the month, e.g. 24
  • var fullyear = ” + presented.getFullYear();
    returns the full year, e.g. 2022
  • var month = ” + presented.getMonth();
    returns the current month where 0 is January, e.g. 3
  • var dayofweek = ” + presented.getDay();
    returns the current month where 0 is Sunday through to 6 for Saturday

For dayofmonth and dayofweek it is easiest to use these to select from an array of options.

For Months use….
var months = [“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”];

For days of the week use….
var daysweek = [“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”];

Then refer to them simply as…..
value = months[dayofmonth];
or
value = daysweek[dayofweek];

You can also reword each month or week day value to whatever format suits your needs.

GET ACCESS TO THE PROJECT FILE FOR THIS TUTORIAL
How do I hide the starting number?

In the Text Layer sourceText expression add underneath everything, the following:

if(ref==0){
value = “”;
}

Is there a way to make this with just text and no numbers? e,g, the start date would be PAST, centre date PRESENT, end date would be FUTURE?

On the bottom of the expression of the SourceText property of the text layer you want to add the following…

if(ref==”0″){
value = “PAST”;
}else if(ref==Math.ceil(effect(“Value Step”)(“Slider”)/2)){
value = “PRESENT”;
}else if(ref == effect(“Value Step”)(“Slider”)){
value = “FUTURE”;
}

Then you can use the Value Step slider control to control what it does. If you set it to a value of 2 then it will show Past, Present, Future with no dates in between. Increasing the Value Step number will make dates appear in between. It will still keep “Present” in the middle of the sequence.

Is there a way to define each date that zooms by including the start and end date?

Yes, you can manually define every single date that appears, though it will eliminate being able to use the value step slider to control what appears.
To make this change you need to replace Text Layer sourceText expression to the following (where you define each value in the dateSource array)…

var dateSource = [“Sept 12th”, “Sept 20th”, “Oct 7th”, “Oct 18th”, “Nov 2nd”, “Nov 9th”];

var step = 100/(dateSource.length-1);
var ref = Math.floor(effect(“Animate”)(“Slider”)/step);
var src = (effect(“Animate”)(“Slider”)%step)/step;

ref = src>0.5 ?ref + 1:ref;

value = dateSource[ref];

How do you add another line of text to animate underneath the dot?

The easiest way would be to duplicate the main text layer then use the anchor point to reposition the text underneath. Then you can set up the text to do whatever you like. If you want static text then get rid of the expression on the sourceText property, otherwise follow the answers of some of the above questions to make the text say different things. The key is that the Value Step property needs to be the same for both text layers, as does the Left, Center, and Right slider values. Otherwise the text won’t animate in line with each other.

How would you make the animation go forward instead of backwards?

This is pretty easy. Simply swap the values in the Left and Right slider controls, this makes the position on the left be on the right, and the right position to be on the left, effectively reversing the animation.

Grab some Merch

Express your inner creative outwardly whilst supporting all that we do...

View Merch store

Need some help

Run into an issue with one of the tutorials or is something not covered in the FAQ?

Contact and Support