02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Delaying without adding animations

You might encounter a scenario where you'd like to add a delay into your timeline without actually triggering any animation. To do this, you could use TimelineLite to trigger events and functions that are correlated to time that are not animating. In this lesson we will discover how to add delays without adding an animation by using the call method.

Video Transcript

00:00Specifically, there isn't a function that delays the timeline, because there is no reason
00:07for it to have, although I would love to have that method, it seems like a logical one.
00:10But you could create a delay in a very easy way using the call method, and I want to
00:15show you how to do that, because it's something that you'll definitely have a scenario where
00:18suddenly you just want to add a delay without it connected to anything.
00:21You might.
00:22Right?
00:23So let's jump into it, let's see how to do it, and in the process continue and improve
00:26our animations.
00:28This lecture is going to be short, to the point, and I just want to talk briefly about the idea
00:33of adding a delay.
00:35What if I wanted to add a delay after this intro animation before the next animation begins?
00:42Now yes, I could go inside, find the next element, which is basically this element here,
00:48and then figure out a way to add that position into it.
00:51Another way is, for example, what if I want to do something, in this case I really do,
00:56and I want to add some sort of something into my element here.
01:00So literally, just by going here into my Geek2 timeline, and just calling a function and
01:06putting it in a later position in my timeline, it will basically push my timeline.
01:11I could be your empty function if I want to, which is basically like a delay call.
01:16But in my case, I'm actually going to set my copy to be that 10 and value and delete
01:20all those spans, because we don't need them anymore.
01:23So I'm going to just go ahead here and just call a new function.
01:26I'll call it onH1, onH1, done, and I'm going to send into it no parameters.
01:38But I'm going to go ahead and set what this will be to be the actual H1 here.
01:43And by the way, we set here H1 so many times that we're probably over-wasting the calls
01:49to jQuery, which is always a good idea to just go ahead, create a quick variable, call
01:54it H1 if that was the name of your object.
01:56Obviously, this is a very generic name, but because we have only one H1, and we're not
02:01planning to build a full-blown web page, it is OK.
02:04But ideally, you probably want to put something that is a little bit more descriptive, because
02:09you definitely could have a scenario where there's more than one H1, and then your
02:13H1 would be overkill.
02:15Now it would be confusing.
02:17Now what I'm doing here, I'm basically reducing the amount of times that we're calling a function,
02:22calling a constructor.
02:23So I'm only calling it once whenever I need it.
02:26That way, I'm not overextending it, over-calling itself.
02:30That's always a positive.
02:31And then the last attribute, if you recall, was the position.
02:34So I could literally say plus equals, let's say, three seconds, and now this is going
02:37to go into that position.
02:38Now if I wanted to, I could have created an empty function here.
02:41Literally I could have even sent here basically a function that's empty if I wanted to.
02:45Because it doesn't have to do anything.
02:47That's enough for me to create some sort of a delay.
02:50But I really want to do something, so I'm going to go right in there, create that function
02:53really quickly.
02:55Because what I really want to create is basically, oops, what I really want to create is a function
03:00that will basically reset the copy there and set it to be 10, which is what I want
03:04it to be.
03:05So I'm going to go to the item itself, and I'm going to, it's a jQuery item,
03:08and I'm going to go ahead to the text itself and define it to be 10 plus that
03:13geek2 dot h1 value.
03:18And that's it.
03:19Once I've done that, it's going to call it, it's going to call it at the third second.
03:24So if I really wanted to, I could have just called it immediately, and then created that
03:29delay, but it doesn't really matter to me.
03:30But I could have very easily just called this function, call this function, and call
03:36it basically immediately when it's happening.
03:38And then create another function and have that call after three seconds creating that
03:41delay that will push the playhead.
03:45And that's it.
03:46That's how I add a delay, a very simple way of adding delays whenever I need to.
03:49And a callback with a delay is even better in our case.
03:51So now if I run it one more time, we'll see that after the initial animation takes place,
03:56we're going to have a delay of three seconds, and not only will we have a delay of three
04:00seconds after those three seconds are over, these spans will disappear, and it's just
04:04going to turn into that original copy that was there, and then it's going to start
04:08that progress down from 10 all the way to two.
04:11So that's it.
04:12That is our topic of adding a delay, literally.
04:18And in the next episode, in the next lecture, we're going to revisit the constructor of
04:24the timeline line, because I want to show you how could you add pre-built animations
04:27that you already have right into your constructor.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!