Start learning with our library of video tutorials taught by experts. Get started

Create a Rotating Carousel with jQuery and Dreamweaver

Adding animated transitions between captions


From:

Create a Rotating Carousel with jQuery and Dreamweaver

with Chris Converse

Video: Adding animated transitions between captions

To create the animation effect for the captions that we saw in the introduction video, let's come over to carousel.js. Now after showCaptions, we are going to add another custom function. Let's type function hideCaptions, beginning and ending parentheses, beginning and ending bracket. So inside of hideCaptions, let's type a dollar sign, beginning and ending parentheses. Inside of the parenthesis two tick marks for a string literal, pound sign, captions.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
Create a Rotating Carousel with jQuery and Dreamweaver
58m 47s Intermediate Feb 02, 2012

Viewers: in countries Watching now:

Learn how to implement and customize an interactive rotating carousel animation with jQuery and Adobe Dreamweaver. Author Chris Converse covers preparing the carousel images and captions, creating the carousel containers with HTML and CSS, and activating the carousel with JavaScript. The course also explains how to add images to the carousel container, set the caption based on the image in focus, and add animated transitions between captions.

Topics include:
  • Exporting graphics from Photoshop
  • Creating the HTML, CSS, and JavaScript files
  • Positioning elements with CSS
  • Using the Roundabout plug-in
  • Activating the carousel callback
  • Detecting the image in focus
  • Adding the final touches
Subjects:
Web Web Design Projects
Software:
Dreamweaver jQuery
Author:
Chris Converse

Adding animated transitions between captions

To create the animation effect for the captions that we saw in the introduction video, let's come over to carousel.js. Now after showCaptions, we are going to add another custom function. Let's type function hideCaptions, beginning and ending parentheses, beginning and ending bracket. So inside of hideCaptions, let's type a dollar sign, beginning and ending parentheses. Inside of the parenthesis two tick marks for a string literal, pound sign, captions.

We are going to target the captions div. Outside of the parentheses, we are going to type .animate, beginning and ending parentheses, semicolon. Inside of the animate parentheses, we am going to type two brackets, inside of the brackets, two tick marks for a string literal. We are going to type opacity. Outside of the tick marks for the string literal but still inside of the brackets, colon, 0. And then outside of the brackets but inside of the parentheses, 250 milliseconds, or one quarter of the second.

So next we are going to modify the showCaption function to bring that opacity backup. So inside of the showCaption function, after the setCaption variable, let's hit some returns. We are going to create a new variable, so var newHeight. We are going to set the equal to dollar sign, parentheses, inside of the parentheses, two tick marks for a string literal, pound sign, captions, outside of the parentheses .height, beginning and ending parentheses, plus, two tick marks for a string literal, then a semicolon, and inside of the string literal, px.

So what this is going to do is calculate the new height of the captions container after we have run these setCaption HTML inside of that object, and then we are going to add the px here for the CSS value. Now that we have calculated the new height, let's hit a Return, hit dollar sign, parentheses, inside of the parentheses, two tick marks for a string literal. We are going to type .caption_container, outside of the parenthesis, .animates.

beginning a new parentheses, semicolon. Inside of the animate parentheses, two brackets. Inside of the brackets, two tick marks for a string literal. I am going to type height. Outside of the string literal but still inside of the brackets, colon, and let's come up here and copy the new height variable, copy that to the clipboard. Let's paste them inside of the brackets. Outside of the brackets, but still inside of the parentheses for animate, comma, 500 for half a second. Then we are going to type another comma, space, function, beginning and ending parentheses, beginning and ending bracket.

This is what's known as a callback function. So after this animation takes place then this function is going to trigger, but this function won't trigger until after the animated state, so we will know that the container has animated to its new state before we fade in the text. And by the way, this caption container has the border on it for the stem, so this gives us the illusion of the stem actually growing. Now inside of the callback function, dollar sign, parentheses, two marks for string literal, pound sign, captions. Outside of the parentheses, .animate, beginning and ending parentheses, semicolon. Inside of the parentheses two brackets, two tick marks for a string literal, opacity. Outside of the string literal but still inside of the brackets, colon, 1, and then outside of the brackets but inside of the parentheses for animate, comma 250.

In order to hook these two functions into our custom buttons, let's come down and select hideCaptions' function name. Let's copy that. Let's scroll up and under our createCustomButtons, we are going to come up here and inside of the nextItem, click function, we are going to add the hideCaptions. And inside of the previous item click function we are going to add hideCaptions. So this means when we click on the next item or previous item, we are going to run the hideCaptions function and then run the custom roundabout function to animate to either next child or previous child.

The second thing we are going to do inside of these custom click events is add a callback to play the showCaption as well so that the buttons will also trigger the caption to be reset. So to do that, under the roundabout for animateToNextChild, outside of the string literal but still inside of the parenthesis, we are going to type comma, space, and let's come down here and copy the showCaption name without the parentheses. Let's paste that here and under animateToPreviousChild, comma, space, and paste that here as well.

So again, each button will now hide the captions, tell the roundabout to animate to either next or previous child, and then once that's done, it will run the showCaption function. So to test this, let's choose File > Save All, switch back to carousel.html, File > Preview in Browser. So now in the browser when I click on one of the buttons, let's click on the left button here, the first time this runs up, you will notice that it just sort of pops into place. But then as I continue to click it, we will have see the type fade away and if we get to a caption that's longer or shorter, we will actually see the animation of the stem growing to accommodate the new text that's being injected in.

And this works for the right arrow as well. Now right now the teapots are not triggering the hide function, so if I click these, they will spin and change the type and the showCaption will animate the new container. But we don't have the hideFunction actually signed to the carousel items. So to modify this, let's go back to our JavaScript file, and what we are going to do inside of our JavaScript file is we are going to create a new button inside of our custom button functions. So after the previous item click event, let's hit Return, and let's type dollar sign, beginning and ending parentheses, two tick marks for a string literal, div#carousel, then space img.

We are going to look for images inside of the carousel area, .click, beginning and ending parentheses, semicolon. Inside of click we are going to type function, parentheses and brackets. We will split this on the brackets, and inside of here we are going to copy the hideCaptions function call and paste it inside of here as well. So basically what we are doing here is in addition to the carousel automatically creating click events on all of the teapots, we are also going to say if any of the images are clicked inside of the carousel, we want to run our function as well. And we want to hook onto the hideCaptions function, so that when we click the teapots they will run the same functions that the buttons are running.

Now let's choose File > Save All. I still have this file open in my browser, so I will switch back to my browser, hit Reload, and now when I click the teapots, I will see the content fade away, the stem will grow, and then we will bring the text back in as well. So now that we have the same behavior happening for both the buttons and the teapots, in the next movie we will look at setting the carousel to default start on a particular teapot and we will set the corresponding caption to show up on load as well.

There are currently no FAQs about Create a Rotating Carousel with jQuery and Dreamweaver.

Share a link to this course
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.
Upgrade now


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.

Upgrade now

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

Congratulations

You have completed Create a Rotating Carousel with jQuery and Dreamweaver.

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


OK
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?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

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 preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



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.

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