Bootstrap Carousel
Description
In this tutorial, you will see how to create a carousel with Bootstrap. This will help you create content sliders, image galleries, and more.
Usage
So you place the items you want to present (such as images) in circular order inside the "carousel-inner" div, and through the "" create navigation for the items. It uses the custom data attribute "data-slide" to navigate to the previous and next items.
You must reference the jquery.js and bootstrap-carousel.js files in the HTML file where you create the carousel.
Bootstrap carousel example
Example
body {
margin: 50px;
}
View the example online
Paging example with old and new
Example
HTML5 and JS Apps
View the example online
Using JavaScript
You can use the JavaScript code below to create a carousel.
$('.carousel').carousel()
Below are the options you can useOption
- interval: Specifies the waiting time between slides, in milliseconds. The value type is number, with a default of 5000. If false, the carousel will not start cycling automatically.
- pause: Specifies that the carousel pauses when the mouse stays over the slide area and resumes when the mouse leaves. The value type is string, with a default of 'hover'.
Below are the carousel methods you can useMethod
- .carousel(options): Initializes the carousel component, accepts an optional options parameter of type object, and starts the slide cycle.
- .carousel('cycle'): Cycles through the frames from left to right.
- .carousel('pause'): Stops the carousel.
- .carousel(number): Positions the carousel at the specified frame (frame indices start at 0, like an array).
- .carousel('prev'): Moves the carousel to the previous frame.
- .carousel('next'): Moves the carousel to the next frame.
There are twoEventsused to enhance the carousel's functionality.
- slide: This event fires immediately after the slide instance method is called.
- slid: This event fires after all slides have been played.
Click here to download all the HTML, CSS, JS, and image files used in this tutorial.