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

Adding images to the carousel container


From:

Create a Rotating Carousel with jQuery

with Chris Converse

Video: Adding images to the carousel container

To start writing our JavaScript, let's switch over to carousel.js. Let's add a few lines in here. And we're going to start off by using jQuery's document ready. So, start with a dollar sign, parentheses, document inside of the parentheses. Outside of the document we're going to type ready, beginning and ending parentheses, semicolon. Inside of ready we're going to type function, beginning and ending parentheses, beginning and ending bracket.
please wait ...
Watch the Online Video Course Create a Rotating Carousel with jQuery
51m 13s Intermediate Feb 02, 2012

Viewers: in countries Watching now:

In this course, author Chris Converse shows how to implement and customize an interactive rotating carousel animation with jQuery. The course 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 Adobe Photoshop
  • Creating the HTML, CSS, and JavaScript files
  • Positioning elements with CSS
  • Using the Roundabout plug-in
  • Controlling the carousel with custom buttons
  • Detecting the image in focus
  • Adding the final touches
Subject:
Web
Software:
jQuery
Author:
Chris Converse

Adding images to the carousel container

To start writing our JavaScript, let's switch over to carousel.js. Let's add a few lines in here. And we're going to start off by using jQuery's document ready. So, start with a dollar sign, parentheses, document inside of the parentheses. Outside of the document we're going to type ready, beginning and ending parentheses, semicolon. Inside of ready we're going to type function, beginning and ending parentheses, beginning and ending bracket.

Let's split the brackets open. So, this is jQuery's built-in document ready function. So, any instructions inside of here won't happen until all of the HTML's been loaded and the document object model of the browser has been complete. So, once our document is loaded the first instruction we're going to do is dollar sign, beginning and ending parentheses, two tick marks inside for string literal, .carousel_data, space, .carousel_item.

Outside of the parentheses we're going to type .each, beginning and ending parentheses, then a semicolon. Inside of the each, we're going to add a function, beginning and ending parentheses, beginning and ending bracket. Let's split that open on the brackets. Inside of the each function we're going to type dollar sign, parentheses, tick marks inside for string literal, pound sign, carousel. Outside of the parentheses .append, beginning and ending parentheses, semicolon.

Inside of append, we'll put a few spaces in here so this is easier to read. We're going to type dollar sign, this, inside of parentheses. Outside of the parentheses, .find, beginning and ending parentheses, two tick marks for string literal, .image. Outside of find but still inside of the parentheses for append, .html, beginning and ending parentheses. So, now what this script is going to do is it's going to look inside of carousel data, find every carousel item, and for each item then it finds it's going to pull the HTML out of the class of image and it's going to put it inside of the ID carousel.

So, after the script loads, all of the images from the carousal data are going to be placed inside of the carousel ID. Once all of those images are in place, we're going to want to actually create the carousel. So, let's get our curser after the document ready, and let's create our own custom function. We're going to call this createCarousel, beginning and ending parentheses and beginning and ending bracket. Let's put that open on the brackets. So, inside of here what we're going to do is type dollar sign, parentheses, tick marks inside for string literal.

We're going to type div, pound, carousel. Then outside of the parentheses, we're going to type .roundabout, beginning and ending parentheses, semicolon. This is the custom function name of the Roundabout plug-in. Inside of the parentheses, let's put two brackets and then let's split the brackets open. Inside of here we're going to set all of the parameters for the roundabout.

The first one we're going to type in is childSelectror. This tells the Roundabout plug-in what items inside of the carousel div ID that it needs to reposition into a circle. So childSelector, colon, space, two tick marks for a string literal. We're going to look for image tags. Let's add a comma. Next line, we're going to set the tilt to -4.5. This is going to give us the 3D effect of the items in the back versus the items in the front. Let's hit a comma. Next line, minimum opacity or minOpacity.

I'm going to set this to 1 because I want my teapots to always be opaque. Next, we're going to set minimum scale or minScale, so that's 45%. This is how small the items get when they're in the back of the carousel. And then lastly, duration, colon, 1200 milliseconds. So, this is the amount of time it takes from an item that's clicked or selected to spin around to be at the forefront of the carousel. Now, since we're creating the carousel inside of our own custom function called createCarousel, let's come down here and select the createCarousel function.

Let's copy the name and inside of the document ready, after we add all of the images that we found inside of the carousel data div, let's paste in the createCarousel function and then put a semicolon. So, once the document ready has happened and we have inserted all of the images that we found in carousel data, we're going to run the createCarousel function, which is going to come down here, look for that carousel div, and then initiate the carousel based on all of these parameters. At this point, let's choose File > Save. Let's come back out to our browser, and let's hit reload.

Now, we'll see that a copy of all of the images from the carousel data div down below are being copied and placed inside of the carousel div ID and the Roundabout plug-in has been initiated so that each one of these items shows up on the carousel. Now kind of built into the plug-in already is the ability to click on these items and have them roll around and become the item in the forefront once they're clicked. So, now that the carousel is being built properly, in the next movie we'll create some JavaScripts that will hook up the right and left arrows so we can use these to rotate the carousel as well.

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

 
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

Congratulations

You have completed Create a Rotating Carousel with jQuery.

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


OK

Upgrade to View Courses Offline

login

With our new Desktop App, Annual Premium Members can download courses for Internet-free viewing.

Upgrade Now

After upgrading, download Desktop App Here.

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:

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.

Start your FREE 10-day trial

Begin learning software, business, and creative skills—anytime,
anywhere—with video instruction from recognized industry experts.
lynda.com provides
Unlimited access to over 4,000 courses—more than 100,000 video tutorials
Expert-led instruction
On-the-go learning. Watch from your computer, tablet, or mobile device. Switch back and forth as you choose.
Start Your FREE Trial Now
 

A trusted source for knowledge.

 

We provide training to more than 4 million people, and our members tell us that lynda.com helps them stay ahead of software updates, pick up brand-new skills, switch careers, land promotions, and explore new hobbies. What can we help you do?

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.