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

Using AttrPlugin when it doesn't work

Most attributes by default will work great on their own, however sometimes they won't and that's exactly when you want to add the AttrPlugin. In this lecture, we will meet a few attributes of SVG that just won't animate without this plugin. By the end of this lecture, you will know everything you need to know about how to work with the AttrPlugin.

Video Transcript

00:00In general, Green Sock is smart enough to be able to figure out what you're animating,
00:05if it's CSS, if it's actually an attribute.
00:08But there are some scenarios where it's just not smart enough and it needs a little bit
00:12of help, a little bit of a quick push, a little bit of a push, I don't even know what
00:16I was trying to say, to be able to figure out that it's actually trying to animate
00:19a property.
00:20And in those scenarios, we're going to use the attribute plugin.
00:23So let's see it in action as we see the point where it actually, Green Sock doesn't
00:29know how to do it.
00:30And we have to use the plugin to be able to sort it out.
00:33Attribute plugin in action.
00:35To do that, I want to show you where basically animations will stop working if you don't
00:39use it.
00:40So let's go ahead into our editor and what I want to do, I'm going to go all the way
00:43up and in our initial animation, what I want to do after we create our slideshow, I want
00:49to immediately after create a quick little tween two.
00:52So I'm going to go ahead to do a tween light and I'm going to do a two.
00:55And what I want to do is I want to send in our button.
00:58And again, if we were doing this more efficiently, we would probably store this button as a variable
01:02and then send it in each place that needs it if we're already calling it more than ones.
01:07So that would be the more efficient way of doing it.
01:09I would go right here, create here circles or the circles, set it, define it as a jQuery
01:19element because we don't, we don't want to call something a function twice that's
01:24creating an object more than the times we need to.
01:27So we could literally just go ahead and descend it as the object if we wanted to.
01:30I'm not going to do that because we're actually wrapping it into jQuery internally there,
01:35but I'm going to go ahead and I'm just going to send that string over again as it is.
01:40But in general, you want to always think about trying to keep your code the most efficient
01:43as you can.
01:44And if you do that over time, your code is going to be really robust and really well
01:48planned.
01:49So next is I want to have a one second animation, but this time around, what I want to animate
01:54is I want to animate my actual center point of my X.
01:57I want them all, I want them all to start at 10, but the thing is that if I go ahead
02:01and just say, Hey, I want all to start at 10 here and I run my application, it's not
02:06going to work.
02:07Not only is it not going to work, we're going to get error here because technically the
02:11property is not animatable.
02:14Now to make it animatable, good luck with us.
02:18Because if whenever we want to add animate attributes directly, we're going to go back
02:22into green sock and we're going to make sure that we have the attribute item auto selected.
02:27If I go ahead here and I just duplicate this new attribute property that was just added
02:33in.
02:34And again, if once I cross that 23 kilobytes, it would be time for me to move to tween max.
02:38But so far we're at 16 kilobytes that are actually of the tween light.
02:43And you'll see that the tween light are 16 and things.
02:46So once we cross over the 23, it'll be time for us to move up and upgrade.
02:50So for now, we're going to stick with our tween with only working with our plugins.
02:54So I'm going to go ahead here, enter our editor, and I'm just literally just going
02:58to paste that code in as well.
03:00That will enable us to have animate attributes of our plugin.
03:04Once we've done that, we're almost done.
03:06The last thing that's left for us to do is actually animate that specific attribute.
03:11Now to animate specific attributes, we're not going to run it this way, because jcore
03:16between light will and between engine will think that we're trying to approach CSS.
03:21So we want to wrap it around with the value at ATTR for attribute.
03:26And we're basically sending that as an object inside.
03:30So literally, we'll have the attribute object.
03:32And obviously, I don't know if obviously, but we could create here an ease if we wanted
03:37to and change our ease, we could create your slight delay.
03:40So let's go ahead and do a slight delay.
03:41And again, notice how the delay is outside, you have your attribute directly, you could
03:46animate attributes, a few attributes at a time, you could animate CSS and attribute at
03:50the same time, we just have to separate them into their buckets.
03:53So that's our attributes.
03:54And if I go ahead and run my application again, we're going to see that now we're going
03:58to get a nice animation, and we're not going to get an error.
04:01Oh, we have your an invalid ATTR tween value.
04:05That's because I had there probably error when I was typing it in.
04:08So let's go back in there and see if I've done something wrong, if I go back in here.
04:13So I'm looking at here and it's ATTR.
04:16That looks okay to me.
04:17And if I look into our code here, I definitely Oh, I need to save it probably I didn't save
04:22my HTML page.
04:24So that makes sense.
04:25And if I click on refresh again, then we'll see that our animation buckled up all into
04:29one place.
04:30So what we really wanted was an animation of from and not an animation of two.
04:35If I go ahead here, save that, go back, click on refresh, we should get our animation
04:41slide out.
04:42It's looking really wicked, I would make it a little bit faster even so maybe do it 0.5.
04:48We have one last thing that we have to fix is that currently when it's animating in nothing
04:52is selected, but our first item is selected by default.
04:55So to fix that, I'm going to go ahead and in our construction of our slideshow, I'm going
05:00to make sure that once we're done with everything, and let me just find that slideshow once
05:05we after we created our slideshow, in our constructor, we're done with everything, we
05:11can configure it all of our buttons and all our issues right here.
05:14What I can do is just go ahead and just call this highlight.
05:17Notice how it doesn't matter where I'm at, because this will happen before anything else
05:22would happen.
05:23And this will basically just make sure that I'm going to actually highlight that button
05:27initially, and you can put it wherever you want based on how you want to order things.
05:32But just by doing that, it's going to automatically Oh, and highlight button is not a function
05:37my bad because that function was not defined yet.
05:40Although it was defined, but because it's a variable scope function, because we're setting
05:45it as a variable, my bad, sorry about that, we have to call this after this, it was constructed.
05:51So I'm going to go ahead and just make sure that I'm going to call it as the last thing
05:53I do in my constructor to make sure that that problem will not repeat itself.
05:58And that's fine, you know, I thought that it would work, I forgot that I wouldn't.
06:02And here we go.
06:03And now that animation worked.
06:04And we have our initial highlight just the way we thought and hat wanted it to be.
06:09So that's it.
06:10We are done with this lecture.
06:12And we're done with the attribute plugin, you're going to use it in these type of scenarios
06:18when you're not animating CSS, and you want to animate attributes.
06:23And they just don't work on their own by default.
06:26And then you would load up that attribute plugin, and that will make it work, which
06:30is wicked.

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!