Bootstrap Carousel (bootstrapcarousel)
The Bootstrap Carousel plug-in is a flexible and responsive way to add a slider to a site. In addition, the content is flexible enough, including images, embedded frames, videos, and any other types of content you want to place. If you want to independently reference the functions of this plug-in, you need to referenceCarousel. js. Alternatively, you can referenceBootstrap. jsOr compressed versionBootstrap. min. js.
Instance
The following is a simple slide. The Bootstrap Carousel plug-in shows a general component of the loop playback element. To implement carousel, you only need to add the Code with this flag. You do not need to use the data attribute. You only need to perform simple class-based development.
<! DOCTYPE html>
The result is as follows:
Optional title
You can use. ItemInternal. Carousel-captionElement to add a title to the slide. You only need to place any optional HTML here. It is automatically aligned and formatted. The following example demonstrates this:
<! DOCTYPE html>
The result is as follows:
Usage
- Data attributes: Using the data attribute, you can easily control the position of Carousel.
- AttributeData-slideAccept keywordsPrevOrNextTo change the position of the slide relative to the current position.
- UseData-slide-To a original moving index at the bottom of the carousel bed,Data-slide-to = "2"The slider is moved to a specific index and the index starts counting from 0.
- Data-ride = "carousel"This attribute is used to mark that the animation starts to play when the page is loaded.
- Using JavaScript: Carousel can be manually called using JavaScript, as shown below:
- $ ('. Invalid usel'). Invalid usel ()
Option
Some options are passed through the data attribute or JavaScript. The following table lists these options:
| Option name |
Type/Default Value |
Data attribute name |
Description |
| Interval |
Number Default Value: 5000 |
Data-interval |
Automatically cycle the amount of time delay between each project. If this parameter is set to false, carousel will not automatically loop. |
| Pause |
String Default Value: "hover" |
Data-pause |
When the mouse enters, the loop is paused. When the mouse leaves, the loop is resumed. |
| Wrap |
Boolean Default Value: true |
Data-wrap |
Whether the carousel is continuous or not. |
Method
The following are some useful methods in the Carousel plug-in:
| Method |
Description |
Instance |
| . Carousel (options) |
Initialize the carousel as an optional options object and start the Loop Project. |
- $ ('# Identifier'). Invalid usel ({
- Interval: 2000
- })
Copy |
| . Carousel ('cycle ') |
From left to right. |
- $ ('# Identifier'). carousel ('cycle ')
Copy |
| . Usel ('pause ') |
Stop the carousel Loop Project. |
- $ ('# Identifier') .. usel ('pause ')
Copy |
| . Carousel (number) |
Loop carousel to a specific frame (counting starts from 0, similar to array ). |
- $ ('# Identifier'). Invalid usel (number)
Copy |
| . Cancusel ('prev ') |
Loop to the previous project. |
- $ ('# Identifier'). Invalid usel ('prev ')
Copy |
| . Carousel ('Next ') |
Loop To the next project. |
- $ ('# Identifier'). incluusel ('Next ')
Copy |
Instance
The following example demonstrates the usage of the method:
<! DOCTYPE html> EventThe following table lists the events to be used in the Carousel plug-in. These events can be used as hooks in functions.
| Event |
Description |
Instance |
| Slide. bs. carousel |
This event is triggered immediately when the slide instance method is called. |
- $ ('# Identifier'). on ('slide. bs. incluusel', function (){
- // Execute some actions...
- })
Copy |
| Slid. bs. carousel |
This event is triggered when slideshow completes the slide transition effect. |
- $ ('# Identifier'). on ('slid. bs. incluusel', function (){
- // Execute some actions...
- })
Copy |
Instance
The following example demonstrates the event usage:
<! DOCTYPE html> The result is as follows: