Учебник по Bootstrap 4

BS4 ГЛАВНАЯ BS4 Начать Контейнеры BS4 Базовая сетка BS4 Типография BS4 Цвета BS4 Таблицы BS4 Изображения BS4 BS4 Джамботрон Оповещения BS4 Кнопки БС4 Группы кнопок BS4 Значки BS4 Индикаторы выполнения BS4 Спиннеры BS4 BS4 Пагинация Группы списков BS4 Карты BS4 Выпадающие списки BS4 Свернуть BS4 BS4 Навс BS4 навигационная панель БС4 Формы Входы БС4 Входные группы BS4 Пользовательские формы BS4 BS4 Карусель BS4 модальный Подсказка BS4 BS4 всплывающее окно BS4 Тост BS4 прокрутки Утилиты BS4 BS4 Flex Иконки BS4 Медиа-объекты BS4 Фильтры BS4

Bootstrap 4 Сетка

Сетевая система BS4 BS4 Сложенный/горизонтальный BS4 Сетка XSмаленький BS4 Малая сетка Сетка BS4 средняя BS4 Сетка большая BS4 Сетка XLarge Примеры сетки BS4

Начальная загрузка 4 Другое

Базовый шаблон BS4 Упражнения BS4 Викторина БС4

Начальная загрузка 4 Ссылка

Все классы JS-оповещение JS-кнопка JS Карусель Свернуть JS Выпадающий список JS Модальный JS JS всплывающее окно JS прокрутка Вкладка JS JS тосты JS-подсказка


Bootstrap 4 JS Карусель


CSS-классы карусели

Учебное пособие по каруселям см. в нашем учебном пособии по Bootstrap Carousel .

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

Через атрибуты data-*

Атрибут data-ride="carousel"активирует карусель.

Атрибуты data-slideи data-slide-toуказывают, к какому слайду перейти.

Атрибут data-slideпринимает два значения: prev или next , а data-slide-toпринимает числа.

Пример

<!-- 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>

Через JavaScript

Включить вручную с помощью:

Пример

// Activate Carousel
$("#myCarousel").carousel();

// Enable Carousel Indicators
$(".item").click(function(){
  $("#myCarousel").carousel(1);
});

// Enable Carousel Controls
$(".carousel-control-prev").click(function(){
  $("#myCarousel").carousel("prev");
});

Параметры карусели

Параметры можно передавать через атрибуты данных или JavaScript. Для атрибутов данных добавьте имя опции к data-, как в 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:

  • true - the carousel can be navigated (next and previous) with the keyboard left and right arrows
  • false - the carousel can NOT be navigated with the keyboard left and right arrows
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

  • true - cycle continuously
  • false - stop at the last item

Карусельные методы

В следующей таблице перечислены все доступные методы карусели.

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

Карусель События

В следующей таблице перечислены все доступные события карусели.

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

События скольжения и скольжения также имеют дополнительные свойства:

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