Bootstrap is offering a remarkable feature of carousel and easy to embed in website. This Bootstrap Carousel Plugin is flexible and responsive and allows images, videos and any kind of content which you want to use within the carousel area.
If you want to implement functionality of this plugin individually, simple include the carousel.js file along the other JS files. Else as we have discussed in the tutorial of Bootstrap Plugin Overview, you can include bootstrap.jsor the minified bootstrap.min.js.
Here is a simple slideshow below shows a generic component for cycling through elements like a carousel. To use the carousel you simple need a markup code. This is only class based development you do not need for data attributes for carousel plugin.
If you want to like add captions to your slides easily with the .carousel-caption element within any .item. Place just about any optional HTML within there and it will be automatically aligned and formatted. Use the following code to display caption in the slideshow:
Via data attributes
Use data attributes to easily control the position of the carousel.
Attribute data-slide accepts the keywords prev or next, which alters the slide position relative to its current position.
Alternatively use data-slide-to to pass a raw slide index to the carousel data-slide-to=”2″, which shifts the slide position to a particular index beginning with 0.
The data-ride=”carousel” attribute is used to mark a carousel as animating starting at page load.
||Data attribute name
|| The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.
||Pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave.
||Whether the carousel should cycle continuously or have hard stops.
Here are some useful methods to use carousel code.
||Initializes the carousel with an optional options object and starts cycling through items.
||Cycles through the carousel items from left to right.
||Stops the carousel from cycling through items.
||Cycles the carousel to a particular frame (0 based, similar to an array).
||Cycles to the previous item.
||Cycles to the next item..
This example shows the usage of above listed methods.
Bootstrap’s carousel class exposes two events for hooking into carousel functionality which are listed below.
Both events have the following additional properties:
- direction: The direction in which the carousel is sliding (either "left" or "right").
- relatedTarget: The DOM element that is being slid into place as the active item.
||This event fires immediately when the slide instance method is invoked..
||This event is fired when the carousel has completed its slide transition.
The following example demonstrates the usage of events: