Carousel
Ib qho slideshow tivthaiv rau kev caij tsheb kauj vab los ntawm cov ntsiab lus-cov duab lossis cov ntawv swb-zoo li lub voj voog.
Lub carousel yog slideshow rau cycling los ntawm ib tug series ntawm cov ntsiab lus, ua nrog CSS 3D transforms thiab me ntsis ntawm JavaScript. Nws ua haujlwm nrog cov duab, ntawv nyeem, lossis kev cai cim. Nws kuj suav nrog kev txhawb nqa rau yav dhau los / tom ntej tswj thiab ntsuas.
Hauv cov browsers uas qhov Page Visibility API tau txais kev txhawb nqa, lub carousel yuav zam zawv zawg thaum lub vev xaib tsis pom rau tus neeg siv (xws li thaum browser tab tsis ua haujlwm, qhov browser qhov rai raug txo qis, thiab lwm yam).
Thov nco ntsoov tias cov carousels nested tsis tau txais kev txhawb nqa, thiab carousels feem ntau tsis ua raws li cov qauv kev siv tau.
Thaum kawg, yog tias koj tab tom tsim peb JavaScript los ntawm qhov chaw, nws xav tauutil.js
.
Carousels tsis cia li normalize swb qhov ntev. Yog li ntawd, tej zaum koj yuav tau siv cov khoom siv ntxiv lossis cov qauv kev cai kom haum rau cov ntsiab lus loj. Thaum carousels txhawb nqa yav dhau los / tom ntej tswj thiab ntsuas, lawv tsis xav tau meej. Ntxiv thiab kho raws li koj pom haum.
Cov .active
chav kawm yuav tsum tau ntxiv rau ib qho ntawm cov swb txwv tsis pub lub carousel yuav tsis pom. Tsis tas li ntawd nco ntsoov teem ib tus cim tshwj xeeb rau ntawm .carousel
kev xaiv tswj, tshwj xeeb tshaj yog tias koj siv ntau lub carousels ntawm ib nplooj ntawv. Kev tswj thiab ntsuas cov ntsiab lus yuav tsum muaj tus data-target
cwj pwm (lossis href
rau kev sib txuas) uas phim tus id ntawm lub .carousel
caij.
Ntawm no yog ib tug carousel nrog slides xwb. Nco ntsoov lub xub ntiag ntawm .d-block
thiab .w-100
ntawm cov duab carousel los tiv thaiv qhov browser default duab sib dhos.
Ntxiv rau hauv cov kev tswj yav dhau los thiab tom ntej:
Koj tuaj yeem ntxiv cov ntsuas rau lub carousel, nrog rau cov tswj, ib yam nkaus.
Ntxiv cov ntawv sau rau koj cov slides yooj yim nrog cov .carousel-caption
khoom hauv ib qho twg .carousel-item
. Lawv tuaj yeem muab zais tau yooj yim ntawm cov chaw saib me me, raws li qhia hauv qab no, nrog rau kev xaiv cov khoom siv hluav taws xob . Peb zais lawv thawj zaug nrog .d-none
thiab coj lawv rov qab rau ntawm cov khoom siv nruab nrab nrog .d-md-block
.
Ntxiv .carousel-fade
rau koj lub carousel rau animate slides nrog ib tug ploj mus hloov tsis yog ib tug swb.
Siv cov ntaub ntawv cwj pwm kom yooj yim tswj txoj hauj lwm ntawm lub carousel. data-slide
lees txais cov lus tseem ceeb prev
lossis next
, uas hloov txoj haujlwm swb txheeb ze rau nws txoj haujlwm tam sim no. Xwb, siv data-slide-to
kom dhau qhov ntsuas qhov ntsuas tsis sib haum mus rau lub carousel data-slide-to="2"
, uas hloov txoj haujlwm swb mus rau qhov ntsuas tshwj xeeb pib nrog 0
.
Tus data-ride="carousel"
cwj pwm yog siv los khij lub carousel li animating pib ntawm nplooj ntawv load. Nws tsis tuaj yeem siv ua ke nrog (rov ua dua thiab tsis tsim nyog) qhia meej JavaScript pib ntawm tib lub carousel.
Hu rau carousel manually nrog:
Cov kev xaiv tuaj yeem dhau los ntawm cov ntaub ntawv tus cwj pwm lossis JavaScript. Rau cov ntaub ntawv tus cwj pwm, ntxiv rau qhov kev xaiv npe rau data-
, xws li hauv data-interval=""
.
Lub npe | Hom | Default | Kev piav qhia |
---|---|---|---|
lub sijhawm | tus lej | 5000 | Lub sijhawm ncua sijhawm ntawm kev caij tsheb kauj vab ib yam khoom. Yog hais tias tsis tseeb, carousel yuav tsis cia li voj voog. |
keyboard | boolean | muaj tseeb | Seb lub carousel yuav tsum teb rau cov xwm txheej keyboard. |
nres | hlua | boolean | "hover" | Yog tias tau teeb tsa Ntawm cov khoom siv kov, thaum teem rau |
caij | txoj hlua | cuav | Autoplays lub carousel tom qab tus neeg siv manually cycles thawj yam khoom. Yog hais tias "carousel", autoplays lub carousel ntawm load. |
qhwv | boolean | muaj tseeb | Txawm hais tias lub carousel yuav tsum tsis tu ncua los yog muaj zog nres. |
Asynchronous txoj kev thiab kev hloov
Txhua txoj kev API yog asynchronous thiab pib hloov pauv . Lawv rov qab mus rau tus neeg hu xov tooj sai li sai tau thaum qhov kev hloov pauv pib tab sis ua ntej nws xaus . Tsis tas li ntawd, ib txoj kev hu rau ib qho kev hloov pauv yuav raug tsis quav ntsej .
Pib lub carousel nrog ib qho kev xaiv xaiv object
thiab pib caij tsheb kauj vab los ntawm cov khoom.
Cycles los ntawm cov khoom carousel ntawm sab laug mus rau sab xis.
Nres lub carousel los ntawm kev caij tsheb kauj vab los ntawm cov khoom.
Cycles lub carousel rau ib lub thav duab tshwj xeeb (0 raws, zoo ib yam li ib qho array). Rov qab mus rau tus neeg hu ua ntej lub hom phiaj khoom tau tshwm sim (piv txwv li ua ntej qhov slid.bs.carousel
xwm txheej tshwm sim).
Lub voj voog mus rau qhov khoom dhau los. Rov qab mus rau tus neeg hu ua ntej qhov khoom dhau los tau tshwm sim (piv txwv li ua ntej qhov slid.bs.carousel
xwm txheej tshwm sim).
Cycles mus rau yam khoom tom ntej. Rov qab mus rau tus neeg hu ua ntej cov khoom tom ntej tau tshwm sim (piv txwv li ua ntej qhov slid.bs.carousel
xwm txheej tshwm sim).
Ua kom lub ntsiab ntawm lub carousel.
Bootstrap's carousel class exposes ob txheej xwm rau hooking rau hauv carousel functionality. Ob qho xwm txheej muaj cov khoom nram qab no ntxiv:
direction
: Cov kev taw qhia uas lub carousel zawv zawg (txawm"left"
los yog"right"
).relatedTarget
: Lub caij DOM uas tau swb rau hauv qhov chaw ua cov khoom nquag.from
: Qhov Performance index ntawm cov khoom tam sim noto
: Qhov Performance index ntawm cov khoom tom ntej
Tag nrho cov xwm txheej carousel raug rho tawm haujlwm ntawm lub carousel nws tus kheej (piv txwv li ntawm <div class="carousel">
).
Hom xwm txheej | Kev piav qhia |
---|---|
swb.bs.carousel | Qhov xwm txheej no tua hluav taws tam sim ntawd thaum tus slide txheej txheem piv txwv raug hu. |
swb.bs.carousel | Qhov kev tshwm sim no raug rho tawm haujlwm thaum lub carousel tau ua tiav nws txoj kev hloov pauv. |
Lub sijhawm hloov pauv ntawm .carousel-item
tuaj yeem hloov pauv nrog $carousel-transition
Sass hloov pauv ua ntej sau lossis cov qauv kev cai yog tias koj siv CSS suav nrog. Yog tias siv ntau qhov kev hloov pauv, xyuas kom meej tias qhov kev hloov pauv hloov tau txhais ua ntej (xws li. transition: transform 2s ease, opacity .5s ease-out
).