Bootstrap 4 JS Carousel
Carousel CSS třídy
Chcete-li získat výukový program o karuselech, přečtěte si náš výukový program pro kolotoč Bootstrap .
Class | Description |
---|---|
.carousel |
Creates a carousel |
.carousel-indicators |
Adds indicators for the carousel. These are the little dots at the bottom of each slide (which indicates how many slides there are in the carousel, and which slide the user are currently viewing) |
.carousel-inner |
Adds slides to the carousel |
.carousel-item |
Specifies the content of each slide |
.carousel-control-prev |
Adds a left (previous) button to the carousel, which allows the user to go back between the slides |
.carousel-control-next |
Adds a right (next) button to the carousel, which allows the user to go forward between the slides |
.carousel-control-prev-icon |
Used together with .carousel-control-prev to create a "previous" button |
.carousel-control-next-icon |
Used together with .carousel-control-next to create a "next" button |
.carousel-caption |
Specifies a caption for the carousel |
.slide |
Adds a CSS transition and animation effect when sliding from one item to the next. Remove this class if you do not want this effect |
Přes data-* Atributy
Atribut data-ride="carousel"
aktivuje karusel.
Atributy data-slide
a data-slide-to
určují, na který snímek se má přejít.
Atribut data-slide
přijímá dvě hodnoty: prev nebo
next , zatímco
data-slide-to
přijímá čísla.
Příklad
<!-- Carousel -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Carousel Indicators -->
<li data-target="#myCarousel" data-slide-to="1"></li>
<!-- Carousel Controls -->
<a class="carousel-control-prev" href="#myCarousel" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
Prostřednictvím JavaScriptu
Povolit ručně pomocí:
Příklad
// Activate Carousel
$("#myCarousel").carousel();
// Enable Carousel Indicators
$(".item").click(function(){
$("#myCarousel").carousel(1);
});
// Enable Carousel Controls
$(".carousel-control-prev").click(function(){
$("#myCarousel").carousel("prev");
});
Možnosti karuselu
Možnosti lze předávat prostřednictvím atributů dat nebo JavaScriptu. U datových atributů připojte název volby k data-, jako v data-interval="".
Name | Type | Default | Description | Try it |
---|---|---|---|---|
interval | number, or the boolean false | 5000 | Specifies the delay (in milliseconds) between each slide. Note: Set interval to false to stop the items from automatically sliding |
|
keyboard | boolean | true | Specifies whether the carousel should react to keyboard events:
|
|
pause | string, or the boolean false | "hover" | Pauses the carousel from going through the next slide when the mouse pointer enters the carousel, and resumes the sliding when the mouse pointer leaves the carousel Note: Set pause to false to stop the ability to pause on hover |
|
wrap | boolean | true | Specifies whether the carousel should go through all slides continuously, or stop at the last slide
|
Karuselové metody
V následující tabulce jsou uvedeny všechny dostupné metody karuselu.
Method | Description | Try it |
---|---|---|
.carousel(options) | Activates the carousel with an option. See options above for valid values | |
.carousel("cycle") | Goes through the carousel items from left to right | |
.carousel("pause") | Stops the carousel from going through items | |
.carousel(number) | Goes to a specified item (zero-based: first item is 0, second item is 1, etc..) | |
.carousel("prev") | Goes to the previous item | |
.carousel("next") | Goes to the next item | |
.carousel("dispose") | Destroys a carousel |
Kolotočové akce
V následující tabulce jsou uvedeny všechny dostupné události karuselu.
Event | Description | Try it |
---|---|---|
slide.bs.carousel | Occurs when the carousel is about to slide from one item to another | |
slid.bs.carousel | Occurs when the carousel has finished sliding from one item to another |
Události slide a slide mají také další vlastnosti:
Property | Description | Try it |
---|---|---|
direction | Returns the direction the carousel is sliding (left or right) | |
relatedTarget | Returns the DOM element that is being slid into place as the active item | |
from | Returns the index of where the previous item came from, when moving on to the next one | |
to | Returns the index of the next item |