Carousel a wɔde yɛ nneɛma
Slideshow afã bi a wɔde sakre fa element ahorow mu—mfonini anaa nsɛm a wɔakyerɛw ho mfonini—te sɛ carousel.
Sɛnea ɛyɛ adwuma
Carousel no yɛ slideshow a wɔde sakre tu fa nsɛm a ɛtoatoa so mu, a wɔde CSS 3D nsakrae ne JavaScript kakra na esii. Ɛde mfonini ahorow, nsɛm, anaa agyiraehyɛde a wɔahyɛ da ayɛ na ɛyɛ adwuma. Ɛsan nso ka mmoa a wɔde ma wɔ kan/a edi hɔ a wɔde di dwuma ne nsɛnkyerɛnnede ahorow ho.
Wɔ browser ahorow a wɔboa Page Visibility API no mu no, carousel no bɛkwati sɛ ɛbɛtwetwe bere a wɛbsaet krataafa no ntumi nhu nea ɔde di dwuma no (te sɛ bere a browser tab no nyɛ adwuma, browser window no ayɛ ketewaa, ne nea ɛkeka ho).
Animation nkɛntɛnso a ɛwɔ saa ade yi mu no gyina prefers-reduced-motion
media asɛmmisa no so. Hwɛ yɛn akwan a wɔfa so nya nneɛma ho nkrataa no fã a wɔatew so no .
Yɛsrɛ wo hu sɛ wɔmfa nested carousels mmoa, na mpɛn pii no carousels nhyia gyinapɛn ahorow a ɛfa akwan a wɔfa so nya nneɛma ho.
Nea etwa to no, sɛ worekyekye yɛn JavaScript no afi fibea a, ɛhwehwɛ sɛutil.js
.
Nhwɛsoɔ
Carousels ntumi nyɛ slide nsusuwii ahorow no sɛnea ɛte ankasa. Sɛnea ɛte no, ebia ɛho behia sɛ wode nneɛma foforo a wɔde di dwuma anaa akwan horow a wɔahyɛ da ayɛ di dwuma na ama woatumi ayɛ nneɛma no kɛse sɛnea ɛfata. Bere a carousels boa controls ne indicators a atwam/a edi hɔ no, ɛnyɛ nea wɔhwehwɛ pefee. Fa ka ho na yɛ nea wopɛ sɛnea wuhu sɛ ɛfata.
Ɛsɛ .active
sɛ wɔde adesuakuw no ka slide ahorow no biako ho anyɛ saa a carousel no renhu. Afei nso hwɛ hu sɛ wode id soronko bi besi hɔ wɔ .carousel
for optional controls no so, titiriw sɛ wode carousels pii redi dwuma wɔ kratafa biako so a. Ɛsɛ sɛ control ne indicator elements no nya data-target
attribute (anaasɛ href
ma links) a ɛne .carousel
element no id hyia.
Slides nkutoo na ɛwɔ hɔ
Carousel a ɛwɔ slides nkutoo ni. Hyɛ .d-block
ne .w-100
wɔ carousel mfonini ahorow so no nsow na amma browser default mfonini ahorow no anhyehyɛ no.
Ne nneɛma a wɔde di dwuma
Sɛ wode ka ho wɔ controls a atwam ne nea edi hɔ no mu:
Ne nsɛnkyerɛnnede ahorow
Wubetumi nso de nsɛnkyerɛnne no aka carousel no ho, aka controls no ho, nso.
Ne nsɛm a wɔakyerɛw wɔ so
Add captions to your slides easily with the .carousel-caption
element within any .carousel-item
. They can be easily hidden on smaller viewports, as shown below, with optional display utilities. We hide them initially with .d-none
and bring them back on medium-sized devices with .d-md-block
.
Crossfade
Add .carousel-fade
to your carousel to animate slides with a fade transition instead of a slide.
Individual .carousel-item
interval
Add data-interval=""
to a .carousel-item
to change the amount of time to delay between automatically cycling to the next item.
Usage
Via data attributes
Use data attributes to easily control the position of the carousel. 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. It cannot be used in combination with (redundant and unnecessary) explicit JavaScript initialization of the same carousel.
Via JavaScript
Call carousel manually with:
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-
, as in data-interval=""
.
Name | Type | Default | Description |
---|---|---|---|
interval | number | 5000 | The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle. |
keyboard | boolean | true | Whether the carousel should react to keyboard events. |
pause | string | boolean | "hover" | If set to On touch-enabled devices, when set to |
ride | string | false | Autoplays the carousel after the user manually cycles the first item. If "carousel", autoplays the carousel on load. |
wrap | boolean | true | Whether the carousel should cycle continuously or have hard stops. |
touch | boolean | true | Whether the carousel should support left/right swipe interactions on touchscreen devices. |
Methods
Asynchronous methods and transitions
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
.carousel(options)
Initializes the carousel with an optional options object
and starts cycling through items.
.carousel('cycle')
Cycles through the carousel items from left to right.
.carousel('pause')
Stops the carousel from cycling through items.
.carousel(number)
Cycles the carousel to a particular frame (0 based, similar to an array). Returns to the caller before the target item has been shown (i.e. before the slid.bs.carousel
event occurs).
.carousel('prev')
Cycles to the previous item. Returns to the caller before the previous item has been shown (i.e. before the slid.bs.carousel
event occurs).
.carousel('next')
Cycles to the next item. Returns to the caller before the next item has been shown (i.e. before the slid.bs.carousel
event occurs).
.carousel('dispose')
Destroys an element’s carousel.
Events
Bootstrap’s carousel class exposes two events for hooking into carousel functionality. Both events have the following additional properties:
direction
: The direction in which the carousel is sliding (either"left"
or"right"
).relatedTarget
: DOM element a wɔretwetwe akɔ ne gyinabea sɛ ade a ɛyɛ adwuma.from
: Ade a ɛwɔ hɔ mprempren no ho indexto
: Ade a edi hɔ no ho index
Wɔtow carousel nsɛm a esisi nyinaa tow gu carousel no ankasa so (kyerɛ sɛ, wɔ <div class="carousel">
).
Nsɛm a Ɛsisii no Su | Nkyerɛmu |
---|---|
slide.bs.carousel a wɔde hyɛ mu | Saa adeyɛ yi tow ntɛm ara bere a slide wɔfrɛ instance kwan no. |
slid.bs.afiri a wɔde hyɛ kar mu | Wɔtow saa adeyɛ yi bere a carousel no awie ne slide nsakrae no. |
Sesa nsakrae bere tenten
Nsakrae bere tenten a .carousel-item
wobetumi asesa ne $carousel-transition
Sass variable ansa na woaboaboa ano anaasɛ custom styles sɛ wode CSS a wɔaboaboa ano no redi dwuma a. Sɛ wɔde nsakraeɛ dodoɔ bi di dwuma a, hwɛ sɛ wɔadi kan akyerɛkyerɛ nsakraeɛ nsakraeɛ no mu (sɛ nhwɛsoɔ no transition: transform 2s ease, opacity .5s ease-out
).