I-Carousel
Icandelo lomboniso wesilayidi sokuhamba ngebhayisekile kwizinto-imifanekiso okanye izilayidi zombhalo-njengecarousel.
I-carousel ngumboniso wesilayidi sokuhamba ngebhayisikile ngoluhlu lomxholo, owakhiwe nge-CSS 3D ukuguqulwa kunye nentwana yeJavaScript. Isebenza ngothotho lwemifanekiso, isicatshulwa, okanye imarkup yesiko. Ikwabandakanya inkxaso yolawulo lwangaphambili / olulandelayo kunye nezalathi.
Kwiziphequluli apho i- Page Visibility API ixhaswa khona, i-carousel iya kuphepheka i-sliding xa iphepha lewebhu lingabonakali kumsebenzisi (njengaxa ithebhu ye-browser ingasebenzi, iwindow yesiphequluli iyancitshiswa, njl. njl.).
Nceda uqaphele ukuba iicarousels ezifakwe kwindlwane azixhaswanga, kwaye iicarousels azihambelani nemigangatho yokufikeleleka.
Okokugqibela, ukuba wakha iJavaScript yethu kwimvelaphi, ifunautil.js
.
Iicarousels azizenzeli ngokuzenzekelayo imilinganiselo yesilayidi. Ngaloo ndlela, kunokufuneka usebenzise izixhobo ezongezelelweyo okanye izitayile zesiko ukuze ulinganise ngokufanelekileyo umxholo. Ngelixa ii-carousels zixhasa ulawulo lwangaphambili/olulandelayo kunye nezalathi, azifuneki ngokucacileyo. Yongeza kwaye wenze ngokwezifiso njengoko ubona kufanelekile.
Qinisekisa ukuseta i-id eyodwa kulawulo .carousel
olukhethwayo, ngakumbi ukuba usebenzisa iicarousel ezininzi kwiphepha elinye.
Nantsi i-carousel enezilayidi kuphela. Qaphela ubukho .d-block
kunye .img-fluid
nemifanekiso ye-carousel ukunqanda ulungelelwaniso lomfanekiso olungagqibekanga lwesikhangeli.
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="..." alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Third slide">
</div>
</div>
</div>
Ukongeza kulawulo lwangaphambili nolulandelayo:
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="..." alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
Unokongeza izikhombisi kwi-carousel, ecaleni kolawulo, kwakhona.
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="..." alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
Into yokuqala esebenzayo iyafuneka
Iklasi .active
kufuneka yongezwe kwesinye sezilayidi. Ngaphandle koko, i-carousel ayiyi kubonakala.
Yongeza ii-captions kwizilayidi zakho ngokulula ngento .carousel-caption
engaphakathi kuyo nayiphi na .carousel-item
. Zinokufihlwa ngokulula kwizibuko zokujonga ezincinci, njengoko kubonisiwe ngezantsi, ngezixhobo zokubonisa ozikhethelayo . Sizifihla ekuqaleni .d-none
kwaye sizibuyisele kwizixhobo ezinobungakanani obuphakathi kunye .d-md-block
.
Sebenzisa iimpawu zedatha ukulawula ngokulula indawo ye-carousel. data-slide
yamkela amagama angundoqo prev
okanye next
, eguqula indawo yesilayidi ngokunxulumene nendawo yaso yangoku. Kungenjalo, sebenzisa data-slide-to
ukudlulisa isalathiso sesilayidi ekrwada kwicarousel data-slide-to="2"
, etshintsha indawo yesilayidi kwisalathiso esithile esiqala nge 0
.
Uphawu data-ride="carousel"
loyelelwano lusetyenziselwa ukuphawula i-carousel njengento ephilayo ukuqala kumthwalo wephepha. Ayinakusetyenziswa ngokudityaniswa ne (ingafunekiyo nengafunekiyo) iJavaScript ecacileyo yokuqaliswa kwecarousel enye.
Fowunela i-carousel ngesandla nge:
Iinketho zinokugqithiswa ngeempawu zedatha okanye iJavaScript. Kuphawu lwedatha, faka igama lokhetho ku data-
, njengakwi data-interval=""
.
Igama | Uhlobo | Ukuhlala kukho | Inkcazo |
---|---|---|---|
isithuba | inani | 5000 | Ubungakanani bexesha lokulibaziseka phakathi kokubhayisela ngokuzenzekelayo into. Ukuba ayiyonyani, i-carousel ayiyi kujikeleza ngokuzenzekelayo. |
ikhibhodi | boolean | yinyani | Nokuba i-carousel kufuneka isabele kwiziganeko ze-keyboard. |
nqumama | umtya | boolean | "bhabha" | Ukuba imiselwe Kwizixhobo ezisebenza ngokuchukumisa, xa zimiselwe |
khwela | umtya | bubuxoki | Idlala ngokuzenzekelayo i-carousel emva kokuba umsebenzisi ajikelise ngesandla into yokuqala. Ukuba "i-carousel", idlala ngokuzenzekelayo i-carousel kumthwalo. |
usonga | boolean | yinyani | Nokuba i-carousel kufuneka iqhubeke ijikeleza okanye ibe neendawo zokumisa nzima. |
Iindlela ze-Asynchronous kunye notshintsho
Zonke iindlela ze-API zi -asynchronous kwaye ziqala utshintsho . Babuyela kumnxeba ngokukhawuleza nje ukuba utshintsho luqalisiwe kodwa ngaphambi kokuba luphele . Ukongeza, ukufowunelwa kwendlela kwicandelo lenguquko kuya kuhoywa .
Uqalisa i-carousel ngeendlela ozikhethelayo object
kwaye uqalise ukukhwela ibhayisekile kwizinto.
Ujikeleza izinto zecarousel ukusuka ekhohlo ukuya ekunene.
Imisa ikhareshi ekukhweleni ibhayisekile kwizinto.
Ukujikelisa i-carousel kwisakhelo esithile (i-0 esekelwe, efana noluhlu). Ubuyela kumnxeba phambi kokuba into ekujoliswe kuyo iboniswe (okt phambi kokuba slid.bs.carousel
isiganeko senzeke).
Imijikelo ukuya kwinto yangaphambili. Ubuyela kumnxeba phambi kokuba kuboniswe into yangaphambili (okt phambi kokuba slid.bs.carousel
isiganeko senzeke).
Biyela ukuya kwinto elandelayo. Ubuyela kumnxeba phambi kokuba kuboniswe into elandelayo (okt phambi kokuba slid.bs.carousel
isiganeko senzeke).
Uyonakalisa i-carousel yento.
Iklasi ye-carousel ye-Bootstrap iveza iminyhadala emibini yokuhuka ekusebenzeni kwecarousel. Zombini ezi ziganeko zineempawu ezongezelelweyo zilandelayo:
direction
: Isalathiso apho icarousel islayida (nokuba"left"
okanye"right"
).relatedTarget
: Isiqalelo seDOM esityibilikiswa kwindawo njengomba osebenzayo.from
: Isalathiso sento yangokuto
: Isalathiso senqaku elilandelayo
Yonke imisitho yecarousel ikhutshwa kwicarousel ngokwayo (okt kwi <div class="carousel">
).
Uhlobo loMnyhadala | Inkcazo |
---|---|
isilayidi.bs.carousel | Esi siganeko sitshatyalaliswa ngoko nangoko xa kusenziwa slide indlela yomzekelo. |
slid.bs.carousel | Esi siganeko sigxothwa xa i-carousel igqibile inguqu yayo yesilayidi. |