jQuery UI Widgets
Illustration by John Hersey

jQuery UI Widgets

with Joe Chellman

Video: Animated behaviors

jQuery UI extends the built-in animation Likewise there's a bounce effect.

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course jQuery UI Widgets
33m 53s Intermediate Nov 11, 2013

Viewers: in countries Watching now:

Despite the possibilities offered in HTML5, there's still a call for customizable widgets that can be used in websites and web apps. jQuery UI, a popular plugin for jQuery, is here to answer that call. Joe Chellman shows how to install the plugin, use the accordion and date picker widgets, and add behaviors that change how existing page elements respond to user input. Finally, you'll apply the concepts you've learned to a typical project you might see coming from a client—a survey form.

This course is a short companion piece to jQuery for Web Designers. See that course for information about building your core jQuery skill set.

Joe Chellman

Animated behaviors

jQuery UI extends the built-in animation capabilities of jQuery Core, pretty extensively. We're going to look at some of the ways that it does that in this movie. So here I have an image and a little box with a colour. The first thing that we'll look at is some built in effects,. The jQuery UI effects library takes some of the existing capabilities and packages them up in ways that are convenient to call in your code. So for example, there's a puff effect. Make the flowers go puff, and they disappear. It's basically just scaling, and fading them out, but it does it all at once, in one named function.

Let's see what that looks like. going to jump down to the bottom of this file, scroll up a little bit, and here it is. I'm triggering this first on the click of this button, and then. I'm just calling the effect method on the selected image. The effect is called puff. I just call it by name with that string. And then I give it a duration, which is 300 milliseconds, in this case. So, it's a nice fast puff and it disappears. Likewise there's a bounce effect. Which does just what you might expect. I have that triggered on that second button. And here it is. The call is almost identical.

I've made it a little longer, and I'm just calling it by its name, bounce. Now, many of these named effects have options that you can pass in. So let's look at the puff effect with a bunch of options set. So I've uncommented this block. And commented out that one liner. Save this. We'll take at how it works, and then we'll take it apart. So, reload over here. And you can see it's a little slower. And then afterwards, it brings the flowers back. So, how does this work? Well, the beginning of it is the same. I'm just calling puff.

And then, I'm also passing in an easing function. jQuery UI, if you include the Effects Library, includes all of the easings that you see in the jQuery Easings Plugin. So, you don't need to install those side by side. If you include jQuery UI and its effects, you don't need the jQuery Easing Plugin separately. And the way you call them is by passing in an object with the name, easing and then the value which is the name of the easing function your're using. Then the duration and then the final argument that the affect method accepts is a function that is a callback that you can call when the animation completes.

So in this case, I'm just saying show this. This of course refers to the element with the ID image that I'm operating on. And just show it again in 500 milliseconds using the built in jQuery show method. And that's what it looks like. So you can look through the documentation to see what options are available for the different effect functions. Note that the arguments can seem to be in a different order at times. Like the duration here is the second argument, while here it's the third. There is a canonical order that the documentation will show you. jQuery is pretty smart about figuring out what arguments map onto which properties you're trying to set, but it's always a good idea to keep things in the expected order.

So, another thing jQuery UI offers is the ability to animate colour. This is something that's not built into jQuery Core, it is technically a numeric proper, so maybe you think it'd be something that you can animate using the animate function. But you need jQuery UI to do that. So, this is what it looks like. On this box I am animating both the background colour and the foreground colour. Anything that jQuery can animate that can have a colour assigned to it, can have its colour animated using this capability. So let's look at that trigger. That's right here. So, this is a DIV with the ID colour me, and I'm just animating both it's foreground colour and it's background colour, to these values.

Over 3.5 seconds and I'm just using the default easing, although I've called it by name. So if I reload that's what it looks like. Now in addition to just being able to animate the colour, I can also animate class transitions. What I mean by that is, in jQuery Core, I can add classes, toggle them, basically do a lot of class manipulation on any element. jQuery UI extends that so that I can animate the properties that change when the class changes. For example, this box has this color. I'm actually going to need to reload this.

It has this color when we start out. And when I add this changed class, using this second trigger, it changes. Now, it didn't animate in this case. The way this works is jQuery UI extends the existing methods so they can accept a duration. So I'm going to add a half second animation duration. And reload. Now when I click Give the Box Class, same thing happens, only it's animated. And this is toggle class, so it works in both directions. And this works on more than just colour. It works on any property that jQuery can animate.

So, scrolling back up to the triggers that work on the flower. Here we go. I have another class called, small. Let's look at what that does. Here's the image div. And here is the small class that I've applied to it. So what we're doing is, we're taking the width down from 450 to 200. And then increasing the border width to five pixels. So if I just click this to add the class, you can see it does what I asked it to, but there's no animation. Scroll down to the trigger, here we are, and now I'm going to add a duration, so that this change will animate.

And I'll change this to toggle, so we can try it in both directions. Okay, I'll save, come back over here, reload, and there we go. Animating it down and then animating it back up. So this works as a nice substitute for having to put your CSS in animate function here in jQuery Code. You can keep all your styles up with your CSS and then when you change those classes, jQuery will animate things for you. If you're a more advanced user of CSS this might look somewhat similar to CSS transitions where you can change classes or respond to things with CSS changes when events happen.

Indeed it is a lot like that. If I drop in these transition properties. And take out the duration on this toggle class so that we're just doing a straight toggle class with no animation from jQuery, and reload. You can see the effect is basically the same. Now, using CSS transitions is not quite as compatible as jQuery, but it does open up the possibility of using other properties that jQuery can't animate. Like, for example. Transformations. So if I add this to my small class now and reload.

Now when I add the class it rotates as well. Now this is something that jQuery can't do. It's a CSS transform that's implemented by the browser. It's not a simple numeric property that jQuery can animate. And of course this works bi-directionally. But, though CSS can do this particular kind of transformation, and jQuery cannot, CSS cannot respond to clicks, and jQuery can. So, you can combine the two in nice ways to get all kinds of interseting effects. So, that's a look at jQuery UI Effects and how you can combine them with CSS to give you a lot of power in animating your pages.

There are currently no FAQs about jQuery UI Widgets.

Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.

Mark all as unwatched Cancel


You have completed jQuery UI Widgets.

Return to your organization's learning portal to continue training, or close this page.

Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.