Bootstrap with CSS
- Bootstrap - Responsive utilities
- Bootstrap - Helper Classes
- Bootstrap - Images
- Bootstrap - Buttons
- Bootstrap - Forms
- Bootstrap - Tables
- Bootstrap - Code
- Bootstrap - Typography
- Bootstrap - CSS Overview
- Bootstrap - Grid System
Bootstrap Layout Components
- Bootstrap - Wells
- Bootstrap - Panels
- Bootstrap - List Group
- Bootstrap - Media Object
- Bootstrap - Progress Bars
- Bootstrap - Alerts
- Bootstrap - Thumbnails
- Bootstrap - Page Header
- Bootstrap - Jumbotron
- Bootstrap - Badges
- Bootstrap - Labels
- Bootstrap - Pagination
- Bootstrap - Breadcrumb
- Bootstrap - Navbar
- Bootstrap - Navigation Elements
- Bootstrap - Input Groups
- Bootstrap - Button Dropdowns
- Bootstrap - Button Groups
- Bootstrap - Dropdowns
- Bootstrap - Glyphicons
Bootstrap Plugins
- Bootstrap - Affix Plugin
- Bootstrap - Carousel Plugin
- Bootstrap - Collapse Plugin
- Bootstrap - Button Plugin
- Bootstrap - Alert Plugin
- Bootstrap - Popover Plugin
- Bootstrap - Tooltip Plugin
- Bootstrap - Tab Plugin
- Bootstrap - Scrollspy Plugin
- Bootstrap - Dropdown Plugin
- Bootstrap - Modal Plugin
- Bootstrap - Transition Plugin
- Bootstrap - Plugins Overview
Bootstrap Demos
- Bootstrap - featured Demo
- Bootstrap - Icons Demo
- Bootstrap - Social Icons Demo
- Bootstrap - Calendar Demo
- Bootstrap - Map Demo
- Bootstrap - Caption Demo
- Bootstrap - Tabbed slider Demo
- Bootstrap - Ajax Demo
- Bootstrap - Admin Interface Demo
- Bootstrap - Alert Demo
- Bootstrap - Time line Demo
- Bootstrap - Slider Demo
- Bootstrap - Material Design Demo
- Bootstrap - Blog Demo
- Bootstrap - Navigation Demo
- Bootstrap - Responsive Demo
- Bootstrap - Images Demo
- Bootstrap - Buttons Demo
- Bootstrap - Form Demo
- Bootstrap - Table Demo
- Bootstrap - Grid Demo
Bootstrap Useful Resources
- Bootstrap - Discussion
- Bootstrap - Useful Resources
- Bootstrap - Quick Guide
- Bootstrap - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Bootstrap - Carousel Plugin
The Bootstrap carousel is a flexible, responsive way to add a spder to your site. In addition to being responsive, the content is flexible enough to allow images, iframes, videos, or just about any type of content that you might want.
If you want to include this plugin functionapty inspanidually, then you will need the carousel.js. Else, as mentioned in the chapter, you can include the bootstrap.js or the minified bootstrap.min.js.
Example
A simple spdeshow below shows a generic component for cycpng through the elements pke a carousel, using the Bootstrap carousel plugin. To implement the carousel, you just need to add the code with the markup. There is no need for data attributes, just simple class-based development.
<span id = "myCarousel" class = "carousel spde"> <!-- Carousel indicators --> <ol class = "carousel-indicators"> <p data-target = "#myCarousel" data-spde-to = "0" class = "active"></p> <p data-target = "#myCarousel" data-spde-to = "1"></p> <p data-target = "#myCarousel" data-spde-to = "2"></p> </ol> <!-- Carousel items --> <span class = "carousel-inner"> <span class = "item active"> <img src = "/bootstrap/images/spde1.png" alt = "First spde"> </span> <span class = "item"> <img src = "/bootstrap/images/spde2.png" alt = "Second spde"> </span> <span class = "item"> <img src = "/bootstrap/images/spde3.png" alt = "Third spde"> </span> </span> <!-- Carousel nav --> <a class = "carousel-control left" href = "#myCarousel" data-spde = "prev">‹</a> <a class = "carousel-control right" href = "#myCarousel" data-spde = "next">›</a> </span>
Optional Captions
You can add captions to your spdes easily with the .carousel-caption element within any .item. Place just about any optional HTML within there and it will be automatically apgned and formatted. The following example demonstrates this −
<span id = "myCarousel" class = "carousel spde"> <!-- Carousel indicators --> <ol class = "carousel-indicators"> <p data-target = "#myCarousel" data-spde-to = "0" class = "active"></p> <p data-target = "#myCarousel" data-spde-to = "1"></p> <p data-target = "#myCarousel" data-spde-to = "2"></p> </ol> <!-- Carousel items --> <span class = "carousel-inner"> <span class = "item active"> <img src = "/bootstrap/images/spde1.png" alt = "First spde"> <span class = "carousel-caption">This Caption 1</span> </span> <span class = "item"> <img src = "/bootstrap/images/spde2.png" alt = "Second spde"> <span class = "carousel-caption">This Caption 2</span> </span> <span class = "item"> <img src = "/bootstrap/images/spde3.png" alt = "Third spde"> <span class = "carousel-caption">This Caption 3</span> </span> </span> <!-- Carousel nav --> <a class = "carousel-control left" href = "#myCarousel" data-spde = "prev">‹</a> <a class = "carousel-control right" href = "#myCarousel" data-spde = "next">›</a>+ </span>
Usage
Via data attributes − Use data attributes to easily control the position of the carousel.
Attribute data-spde accepts the keywords prev or next, which alters the spde position relative to its current position.
Use data-spde-to to pass a raw spde index to the carousel data-spde-to = "2", which shifts the spde position to a particular index beginning with 0.
The data-ride = "carousel" attribute is used to mark a carousel as an animation starting at page load.
Via JavaScript − The carousel can be manually called with JavaScript as below −
$( .carousel ).carousel()
Options
There are certain, options which can be passed via data attributes or JavaScript are psted in the following table −
Option Name | Type/Default Value | Data attribute name | Description |
---|---|---|---|
interval | number Default − 5000 | data-interval | The amount of time to delay between automatically cycpng an item. If false, carousel will not automatically cycle. |
pause | string Default − "hover" | data-pause | Pauses the cycpng of the carousel on mouseenter and resumes the cycpng of the carousel on mouseleave. |
wrap | boolean Default − true | data-wrap | Whether the carousel should cycle continuously or have hard stops. |
Methods
Here is a pst of useful methods that can be used with carousel code.
Method | Description | Example |
---|---|---|
.carousel(options) | Initiapzes the carousel with an optional options object and starts cycpng through items. |
$( #identifier ).carousel({ interval: 2000 }) |
.carousel( cycle ) | Cycles through the carousel items from left to right. |
$( #identifier ).carousel( cycle ) |
.carousel( pause ) | Stops the carousel from cycpng through items. |
$( #identifier )..carousel( pause ) |
.carousel(number) | Cycles the carousel to a particular frame (0 based, similar to an array). |
$( #identifier ).carousel(number) |
.carousel( prev ) | Cycles to the previous item. |
$( #identifier ).carousel( prev ) |
.carousel( next ) | Cycles to the next item. |
$( #identifier ).carousel( next ) |
Example
The following example demonstrates the usage of methods −
<span id = "myCarousel" class = "carousel spde"> <!-- Carousel indicators --> <ol class = "carousel-indicators"> <p data-target = "#myCarousel" data-spde-to = "0" class = "active"></p> <p data-target = "#myCarousel" data-spde-to = "1"></p> <p data-target = "#myCarousel" data-spde-to = "2"></p> </ol> <!-- Carousel items --> <span class = "carousel-inner"> <span class = "item active"> <img src = "/bootstrap/images/spde1.png" alt = "First spde"> </span> <span class = "item"> <img src = "/bootstrap/images/spde2.png" alt = "Second spde"> </span> <span class = "item"> <img src = "/bootstrap/images/spde3.png" alt = "Third spde"> </span> </span> <!-- Carousel nav --> <a class = "carousel-control left" href = "#myCarousel" data-spde = "prev">‹</a> <a class = "carousel-control right" href = "#myCarousel" data-spde = "next">›</a> <!-- Controls buttons --> <span style = "text-apgn:center;"> <input type = "button" class = "btn prev-spde" value = "Previous Spde"> <input type = "button" class = "btn next-spde" value = "Next Spde"> <input type = "button" class = "btn spde-one" value = "Spde 1"> <input type = "button" class = "btn spde-two" value = "Spde 2"> <input type = "button" class = "btn spde-three" value = "Spde 3"> </span> </span> <script> $(function() { // Cycles to the previous item $(".prev-spde").cpck(function() { $("#myCarousel").carousel( prev ); }); // Cycles to the next item $(".next-spde").cpck(function() { $("#myCarousel").carousel( next ); }); // Cycles the carousel to a particular frame $(".spde-one").cpck(function() { $("#myCarousel").carousel(0); }); $(".spde-two").cpck(function() { $("#myCarousel").carousel(1); }); $(".spde-three").cpck(function() { $("#myCarousel").carousel(2); }); }); </script>
Events
Bootstrap s carousel class exposes two events for hooking into carousel functionapty which are psted in the following table.
Event | Description | Example |
---|---|---|
spde.bs.carousel | This event fires immediately when the spde instance method is invoked. |
$( #identifier ).on( spde.bs.carousel , function () { // do something }) |
spd.bs.carousel | This event is fired when the carousel has completed its spde transition. |
$( #identifier ).on( spd.bs.carousel , function () { // do something }) |
Example
The following example demonstrates the usage of events −
<span id = "myCarousel" class = "carousel spde"> <!-- Carousel indicators --> <ol class = "carousel-indicators"> <p data-target = "#myCarousel" data-spde-to = "0" class = "active"></p> <p data-target = "#myCarousel" data-spde-to = "1"></p> <p data-target = "#myCarousel" data-spde-to = "2"></p> </ol> <!-- Carousel items --> <span class = "carousel-inner"> <span class = "item active"> <img src = "/bootstrap/images/spde1.png" alt = "First spde"> </span> <span class = "item"> <img src = "/bootstrap/images/spde2.png" alt = "Second spde"> </span> <span class = "item"> <img src = "/bootstrap/images/spde3.png" alt = "Third spde"> </span> </span> <!-- Carousel nav --> <a class = "carousel-control left" href = "#myCarousel" data-spde = "prev">‹</a> <a class = "carousel-control right" href = "#myCarousel" data-spde = "next">›</a> </span> <script> $(function() { $( #myCarousel ).on( spde.bs.carousel , function () { alert("This event fires immediately when the spde instance method" +"is invoked."); }); }); </script>Advertisements