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.
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).
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
.
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.
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.
Sɛ wode ka ho wɔ controls a atwam ne nea edi hɔ no mu:
Wubetumi nso de nsɛnkyerɛnne no aka carousel no ho, aka controls no ho, nso.
Fa nsɛm a wɔakyerɛw no ka wo slide ahorow no ho mmerɛw denam .carousel-caption
element a ɛwɔ biara mu .carousel-item
no so . Wobetumi de asie ntɛm wɔ viewports nketewa so, sɛnea wɔakyerɛ wɔ ase ha no, a optional display utilities . Yɛde sie mfiase no .d-none
na yɛde san ba wɔ mfiri akɛse a ɛwɔ mfinimfini so de .d-md-block
.
Fa ka .carousel-fade
wo carousel ho na ama slide ahorow no ayɛ anigye denam fade nsakrae so sen sɛ wode slide bedi dwuma.
Fa data attributes di dwuma na ama ɛnyɛ den sɛ wobɛhwɛ carousel no gyinabea so. data-slide
gye nsɛmfua titiriw prev
anaa next
, a ɛsakra slide gyinabea no toto ne mprempren gyinabea no ho. Sɛnea ɛbɛyɛ foforo no, fa di dwuma data-slide-to
de fa raw slide index kɔ carousel no so data-slide-to="2"
, a ɛdannan slide no gyinabea kɔ index pɔtee bi a efi ase wɔ 0
.
Wɔde data-ride="carousel"
su no di dwuma de hyɛ carousel agyirae sɛ ɛyɛ animating a efi ase wɔ kratafa a wɔde hyɛ mu. Wontumi mfa nni dwuma nka (redundant ne nea ɛho nhia) pefee JavaScript mfiase a ɛwɔ carousel koro no ara ho.
Frɛ carousel denam nsa so de:
Wobetumi afa data attributes anaa JavaScript so de nneɛma a wobɛpaw no akɔ. Sɛ wopɛ data su ahorow a, fa option din no ka ho data-
, sɛnea ɛwɔ data-interval=""
.
Din | Korɔ | Mfiaseɛ | Nkyerɛmu |
---|---|---|---|
ntamgyinafo | nɔma | 5000 na ɛwɔ hɔ | Bere dodow a ɛsɛ sɛ wɔtwentwɛn so wɔ ade bi a wɔde sakre tu kwan ankasa ntam. Sɛ ɛyɛ atoro a, carousel renkyinkyin ne ho. |
keyboard so nsɛm | boolean ho asɛm | nokorɛ | Sɛ ebia ɛsɛ sɛ carousel no yɛ n’ade wɔ nsɛm a esisi wɔ keyboard so no ho anaa. |
home so | ahama | boolean ho asɛm | "hover" no. | Sɛ wode si Wɔ mfiri a wɔde nsa ka so no so no, sɛ wode si |
twi | ahoma | ɛnyɛ ampa | Autoplays carousel no bere a nea ɔde di dwuma no de ne nsa abɔ ade a edi kan no akyi. Sɛ "carousel", autoplays carousel no wɔ adesoa so. |
kyekyere ho | boolean ho asɛm | nokorɛ | Sɛ́ ebia ɛsɛ sɛ carousel no di sakre bere nyinaa anaasɛ ɛwɔ gyinabea a ɛyɛ den. |
Asynchronous akwan ne nsakrae ahorow
API akwan nyinaa yɛ asynchronous na ɛhyɛ nsakrae ase . Wɔsan kɔ nea ɔfrɛɛ no no nkyɛn bere a wɔafi nsakrae no ase ara pɛ nanso ansa na aba awiei . Bio nso, wobebu ani agu ɔkwan a wɔfa so frɛ ade bi a ɛresakra so no so .
Initializes carousel ne optional options object
na ofi ase sakre fa nneɛma mu.
Kyinkyin fa carousel nneɛma no mu fi benkum kɔ nifa.
Siw carousel no kwan sɛ ɛnsɛ sɛ ɔde sakre fa nneɛma mu.
Cycles carousel no kɔ frame pɔtee bi so (0 a egyina so, te sɛ array). San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔakyerɛ ade a wɔde asi wɔn ani so no (kyerɛ sɛ ansa na slid.bs.carousel
asɛm no asi).
Kyinkyin kɔ ade a atwam no so. San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔakyerɛ ade a atwam no (kyerɛ sɛ ansa na slid.bs.carousel
asɛm no asi).
Kyinkyin kɔ ade a edi hɔ no so. San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔakyerɛ ade a edi hɔ no (kyerɛ sɛ ansa na slid.bs.carousel
asɛm no asi).
Ɔsɛe element bi carousel.
Bootstrap carousel adesuakuw no da nsɛm abien a esisi ma hooking kɔ carousel dwumadi mu adi. Nsɛm abien no nyinaa wɔ nneɛma foforo a edidi so yi:
direction
: Ɔkwan a carousel no retwe ("left"
anaasɛ"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. |
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
).