Viewers: in countries Watching now:
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.
There are currently no FAQs about Create a Rotating Carousel with jQuery.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.