I-Carousel
Ingxenye yombukiso wesilayidi yokuhamba ngebhayisikili ezintweni—izithombe noma amaslayidi ombhalo—njenge-carousel.
Isebenza kanjani
I-carousel iwumbukiso wesilayidi sokuhamba ngebhayisikili ngochungechunge lokuqukethwe, olwakhiwe ngezinguquko ze-CSS 3D kanye ne-JavaScript encane. Isebenza ngochungechunge lwezithombe, umbhalo, noma imakhaphu yangokwezifiso. Kuhlanganisa futhi nokusekelwa kwezilawuli zangaphambilini/ezilandelayo nezinkomba.
Ezipheqululini lapho i- Page Visibility API isekelwa khona, i-carousel izogwema ukuslayida lapho ikhasi lewebhu lingabonakali kumsebenzisi (njengalapho ithebhu yesiphequluli ingasebenzi, iwindi lesiphequluli lincishiswa, njll.).
prefers-reduced-motion
embuzweni wemidiya. Bona ingxenye
yokunyakaza encishisiwe yemibhalo yethu yokufinyeleleka .
Sicela uqaphele ukuthi ama-carousel afakwe esidlekeni awasekelwe, futhi ama-carousels ngokuvamile awahambisani nezindinganiso zokufinyeleleka.
Isibonelo
Ama-carousels awazimisi ngokuzenzakalelayo ubukhulu besilayidi. Kanjalo, ungase udinge ukusebenzisa izinsiza ezengeziwe noma izitayela zangokwezifiso ukuze usayizi ofanele wokuqukethwe. Nakuba ama-carousels esekela izilawuli zangaphambilini/ezilandelayo nezinkomba, azidingeki ngokusobala. Engeza futhi wenze ngokwezifiso njengoba ubona kufanelekile.
Ikilasi .active
lidinga ukwengezwa kwesinye sezilayidi ngaphandle kwalokho i-carousel ngeke ibonakale. Futhi qiniseka ukuthi usetha okuhlukile id
kuzilawuli .carousel
ozikhethela, ikakhulukazi uma usebenzisa ama-carousel amaningi ekhasini elilodwa. Izinto zokulawula nezinkomba kufanele zibe data-bs-target
nesibaluli (noma sezixhumanisi href
) esifana nesici.id
.carousel
Amaslayidi kuphela
Nali i-carousel enamaslayidi kuphela. Qaphela ukuba khona kwezithombe .d-block
kanye .w-100
naku-carousel ukuze uvimbele ukuqondanisa okuzenzakalelayo kwesiphequluli.
<div id="carouselExampleSlidesOnly" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
</div>
</div>
Ngezilawuli
Yengeza kuzilawuli zangaphambilini nezilandelayo. Sincoma ukusebenzisa ama <button>
-elementi, kodwa ungasebenzisa ama- <a>
elementi ane- role="button"
.
<div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Ngezinkomba
Ungakwazi futhi ukwengeza izinkomba ku-carousel, eduze nezilawuli, futhi.
<div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Ngamagama-ncazo
Engeza amagama-ncazo kumaslayidi akho kalula nge- .carousel-caption
elementi ngaphakathi kwanoma iyiphi .carousel-item
. Angafihlwa kalula ezindaweni zokubuka ezincane, njengoba kuboniswe ngezansi, ngezinsiza zokubonisa ozikhethela . Sizifihla ekuqaleni .d-none
futhi sizibuyisele kumadivayisi anosayizi omaphakathi ane- .d-md-block
.
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
I-Crossfade
Engeza .carousel-fade
ku-carousel yakho ukuze uphilise amaslayidi ngoshintsho olufiphele esikhundleni sesilayidi.
<div id="carouselExampleFade" class="carousel slide carousel-fade" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleFade" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleFade" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
.carousel-item
Isikhawu somuntu ngamunye
Engeza data-bs-interval=""
ku-a .carousel-item
ukuze ushintshe inani lesikhathi sokulibaziseka phakathi kokuhamba ngebhayisikili ngokuzenzakalelayo ukuya entweni elandelayo.
<div id="carouselExampleInterval" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active" data-bs-interval="10000">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item" data-bs-interval="2000">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Khubaza ukuswayipha kokuthinta
Ama-carousels asekela ukuswayiphela kwesokunxele/kwesokudla kumadivayisi esikrini esithintwayo ukuze ahambe phakathi kwamaslayidi. Lokhu kungakhutshazwa kusetshenziswa data-bs-touch
isibaluli. Isibonelo esingezansi naso asibandakanyi data-bs-ride
isibaluli futhi data-bs-interval="false"
sinaso asidlali ngokuzenzakalela.
<div id="carouselExampleControlsNoTouching" class="carousel slide" data-bs-touch="false" data-bs-interval="false">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControlsNoTouching" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControlsNoTouching" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Okuhlukile okumnyama
Engeza .carousel-dark
kwezilawuli .carousel
ezimnyama, izinkomba, namagama-ncazo. Izilawuli zihlanekezelwe ekugcwaliseni kwazo okumhlophe okuzenzakalelayo ngesakhiwo se- filter
CSS. Amazwibela nezilawuli zinokuhlukahluka okwengeziwe kwe-Sass okwenza ngendlela oyifisayo color
i- background-color
.
<div id="carouselExampleDark" class="carousel carousel-dark slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active" data-bs-interval="10000">
<img src="..." class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item" data-bs-interval="2000">
<img src="..." class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Inguquko yangokwezifiso
Ubude besikhathi soshintsho .carousel-item
lungashintshwa ngokuhluka kwe- $carousel-transition-duration
Sass ngaphambi kokuhlanganiswa noma izitayela zangokwezifiso uma usebenzisa i-CSS ehlanganisiwe. Uma izinguquko eziningi zisetshenziswa, qiniseka ukuthi uguquko luchazwa kuqala (isb. transition: transform 2s ease, opacity .5s ease-out
).
Sass
Okuguquguqukayo
$carousel-control-color: $white;
$carousel-control-width: 15%;
$carousel-control-opacity: .5;
$carousel-control-hover-opacity: .9;
$carousel-control-transition: opacity .15s ease;
$carousel-indicator-width: 30px;
$carousel-indicator-height: 3px;
$carousel-indicator-hit-area-height: 10px;
$carousel-indicator-spacer: 3px;
$carousel-indicator-opacity: .5;
$carousel-indicator-active-bg: $white;
$carousel-indicator-active-opacity: 1;
$carousel-indicator-transition: opacity .6s ease;
$carousel-caption-width: 70%;
$carousel-caption-color: $white;
$carousel-caption-padding-y: 1.25rem;
$carousel-caption-spacer: 1.25rem;
$carousel-control-icon-width: 2rem;
$carousel-control-prev-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='#{$carousel-control-color}'><path d='M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z'/></svg>");
$carousel-control-next-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='#{$carousel-control-color}'><path d='M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z'/></svg>");
$carousel-transition-duration: .6s;
$carousel-transition: transform $carousel-transition-duration ease-in-out; // Define transform transition first if using multiple transitions (e.g., `transform 2s ease, opacity .5s ease-out`)
$carousel-dark-indicator-active-bg: $black;
$carousel-dark-caption-color: $black;
$carousel-dark-control-icon-filter: invert(1) grayscale(100);
Ukusetshenziswa
Ngezibaluli zedatha
Sebenzisa izibaluli zedatha ukuze ulawule kalula ukuma kwe-carousel. data-bs-slide
yamukela amagama angukhiye prev
noma next
, eshintsha indawo yesilayidi ngokuhlobene nendawo yaso yamanje. Kungenjalo, sebenzisa data-bs-slide-to
ukudlulisa inkomba yesilayidi eluhlaza ku-carousel data-bs-slide-to="2"
, eshintsha indawo yesilayidi ibe inkomba ethile eqala ngo- 0
.
Isibaluli data-bs-ride="carousel"
sisetshenziselwa ukumaka i-carousel njengokugqwayiza kusukela ekulayishweni kwekhasi. Uma ungasebenzisi data-bs-ride="carousel"
ukuqalisa i-carousel yakho, kufanele uyiqalise ngokwakho. Ngeke isetshenziswe kuhlanganiswe (nokungadingeki nokungadingeki) ukuqaliswa okucacile kwe-JavaScript kwe-carousel efanayo.
Nge-JavaScript
Shayela i-carousel ngokwenza:
var myCarousel = document.querySelector('#myCarousel')
var carousel = new bootstrap.Carousel(myCarousel)
Izinketho
Izinketho zingadluliswa ngezibaluli zedatha noma i-JavaScript. Ukuze uthole izibaluli zedatha, faka igama lenketho kokuthi data-bs-
, njengaku data-bs-interval=""
.
Igama | Uhlobo | Okuzenzakalelayo | Incazelo |
---|---|---|---|
interval |
inombolo | 5000 |
Inani lesikhathi sokubambezeleka phakathi kokuhamba ngebhayisikili ngokuzenzakalelayo into. Uma false , i-carousel ngeke ijikeleze ngokuzenzakalelayo. |
keyboard |
boolean | true |
Ukuthi i-carousel kufanele sisabele emicimbini yekhibhodi. |
pause |
umucu | boolean | 'hover' |
Uma kusethelwe ku- Kumadivayisi anikwe amandla ukuthinta, uma kusethelwe ku- |
ride |
umucu | boolean | false |
Idlala ngokuzenzakalela i-carousel ngemuva kokuthi umsebenzisi ajikelezise mathupha into yokuqala. Uma kusethelwe ku- 'carousel' , idlala ngokuzenzakalela i-carousel elayishiwe. |
wrap |
boolean | true |
Ukuthi i-carousel kufanele ijikeleze ngokuqhubekayo noma ibe nokuma kanzima. |
touch |
boolean | true |
Ukuthi i-carousel kufanele isekele ukusebenzisana kokuswayipha kwesokunxele/kwesokudla kumadivayisi wesikrini esithintwayo. |
Izindlela
Izindlela ze-Asynchronous kanye noshintsho
Zonke izindlela ze-API azivumelanisi futhi ziqala inguquko . Babuyele kofonayo uma sekuqalwa uguquko kodwa lungakapheli . Ngokungeziwe, ikholi yendlela engxenyeni yoshintsho izozitshwa .
Bheka imibhalo yethu ye-JavaScript ukuze uthole ulwazi olwengeziwe .
Ungakha isenzakalo se-carousel nomakhi we-carousel, isibonelo, ukuze uqalise ngezinketho ezengeziwe futhi uqale ukuhamba ngebhayisikili ngokusebenzisa izinto:
var myCarousel = document.querySelector('#myCarousel')
var carousel = new bootstrap.Carousel(myCarousel, {
interval: 2000,
wrap: false
})
Indlela | Incazelo |
---|---|
cycle |
Izungeza izinto ze-carousel ukusuka kwesokunxele kuye kwesokudla. |
pause |
Imisa i-carousel ekuhambeni ngebhayisikili ezintweni. |
prev |
Imijikelezo eya entweni edlule. Ibuyela kofonayo ngaphambi kokuba kuboniswe into yangaphambilini (isb, ngaphambi kokuba slid.bs.carousel kwenzeke umcimbi). |
next |
Imijikelezo eya entweni elandelayo. Ibuyela kofonayo ngaphambi kokuba kuboniswe into elandelayo (isb, ngaphambi kokuba slid.bs.carousel kwenzeke umcimbi). |
nextWhenVisible |
Ungajikelezi i-carousel uye kwelinye lapho ikhasi lingabonakali noma i-carousel noma umzali wayo engabonakali. Ibuyela kofonayo ngaphambi kokuthi kuboniswe into eqondiwe |
to |
Ibiyela i-carousel kuhlaka oluthile (okusekelwe ngo-0, okufana namalungu afanayo). Ibuyela koshaya ucingo ngaphambi kokuba kuboniswe into eqondiwe (isb, ngaphambi kokuba slid.bs.carousel kwenzeke umcimbi). |
dispose |
Icekela phansi i-carousel yento. (Isusa idatha egciniwe kusici se-DOM) |
getInstance |
Indlela emile ekuvumela ukuthi uthole isibonelo se-carousel esihlotshaniswa nento ye-DOM, ungayisebenzisa kanje:bootstrap.Carousel.getInstance(element) |
getOrCreateInstance |
Indlela emile ebuyisela isenzakalo se-carousel esihlotshaniswa nento ye-DOM noma idale entsha uma kwenzeka ingaqaliswanga. Ungayisebenzisa kanje:bootstrap.Carousel.getOrCreateInstance(element) |
Imicimbi
Ikilasi le-carousel le-Bootstrap lidalula imicimbi emibili yokuxhunywa ekusebenzeni kwe-carousel. Yomibili imicimbi inezimpawu ezengeziwe ezilandelayo:
direction
: Isiqondiso lapho i-carousel ishelela khona ("left"
noma"right"
).relatedTarget
: I-elementi ye-DOM eslayishwa endaweni njengento esebenzayo.from
: Inkomba yento yamanjeto
: Inkomba yento elandelayo
Yonke imicimbi ye-carousel idutshulwa ku-carousel ngokwayo (okungukuthi ku- <div class="carousel">
).
Uhlobo lomcimbi | Incazelo |
---|---|
slide.bs.carousel |
Imililo ngokushesha lapho slide indlela yesibonelo isetshenziswa. |
slid.bs.carousel |
Ixoshwe lapho i-carousel isiqedile ukuguqulwa kwamaslayidi. |
var myCarousel = document.getElementById('myCarousel')
myCarousel.addEventListener('slide.bs.carousel', function () {
// do something...
})