Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding images to the carousel container

From: Create a Rotating Carousel with jQuery

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.

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.

Show transcript

This video is part of

Image for Create a Rotating Carousel with jQuery
Create a Rotating Carousel with jQuery

18 video lessons · 8451 viewers

Chris Converse
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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

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
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
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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.