Carousel
Karolo ea li-slideshow bakeng sa ho tsamaea ka libaesekele-litšoantšo kapa li-slide tsa mongolo-joaloka carousel.
Kamoo e sebetsang kateng
Carousel ke slideshow ea ho palama baesekele ka har'a letoto la litaba, e hahiloeng ka li-transform tsa CSS 3D le JavaScript e nyane. E sebetsa ka letoto la litšoantšo, mongolo, kapa letšoao la tloaelo. E boetse e kenyelletsa tšehetso bakeng sa litsamaiso tse fetileng / tse latelang le matšoao.
Ho li-browser moo API ea Ponahalo ea Leqephe e tšehelitsoeng, carousel e tla qoba ho thella ha leqephe la webo le sa bonahale ho mosebelisi (joalo ka ha sebatli se sa sebetse, fensetere ea sebatli e fokotsehile, joalo-joalo).
prefers-reduced-motion
potso ea media. Sheba karolo e
fokolitsoeng ea motsamao oa litokomane tsa phihlello ea rona .
Ka kopo hlokomela hore li-carousels tse kentsoeng lihlaheng ha li tšehetsoe, 'me li-carousels hangata ha li tsamaellane le maemo a phihlello.
Qetellong, haeba u theha JavaScript ea rona ho tsoa mohloling, e hlokautil.js
.
Mohlala
Li-carousels ha li iketsetse litekanyo tsa li-slide ka botsona. Ka hona, ho ka 'na ha hlokahala hore u sebelise lisebelisoa tse eketsehileng kapa mekhoa e tloaelehileng ho etsa boholo bo nepahetseng. Leha li-carousel li tšehetsa litsamaiso le matšoao a fetileng/tse latelang, ha li hlokehe ka ho hlaka. Eketsa 'me u iketsetse kamoo u bonang ho loketse kateng.
Sehlopha .active
se hloka ho kenyelletsoa ho e 'ngoe ea li-slide ho seng joalo carousel e ke ke ea bonahala. Hape etsa bonnete ba hore u beha e ikhethang bakeng id
sa .carousel
taolo ea boikhethelo, haholo haeba u sebelisa li-carousel tse ngata leqepheng le le leng. Taolo le likarolo tsa matšoao li tlameha ho ba le data-target
tšobotsi (kapa href
bakeng sa likhokahano) tse tsamaellanang id
le .carousel
element.
Li-slide feela
Ke ena carousel e nang le li-slide feela. Ela hloko boteng ba litšoantšo tsa carousel .d-block
le .w-100
tsa carousel ho thibela tlhophiso ea setšoantšo sa kamehla.
<div id="carouselExampleSlidesOnly" class="carousel slide" data-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>
Ka taolo
Eketsa litaolo tse fetileng le tse latelang. Re khothaletsa ho sebelisa <button>
likarolo, empa hape o ka sebelisa <a>
likarolo tse nang le role="button"
.
<div id="carouselExampleControls" class="carousel slide" data-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-target="#carouselExampleControls" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-target="#carouselExampleControls" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</button>
</div>
Ka matšoao
U ka boela ua eketsa matšoao ho carousel, hammoho le litsamaiso, hape.
<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 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-target="#carouselExampleIndicators" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-target="#carouselExampleIndicators" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</button>
</div>
Ka litlhaloso
Kenya litlhaloso ho li-slide tsa hau habonolo ka .carousel-caption
karolo e ka har'a .carousel-item
. Li ka patoa habonolo libakeng tse nyane tsa pono, joalo ka ha ho bonts'itsoe ka tlase, ka lisebelisoa tsa boikhethelo . Re li pata qalong ka .d-none
le ho li khutlisetsa ka lisebelisoa tsa boholo bo mahareng tse nang le .d-md-block
.
<div id="carouselExampleCaptions" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleCaptions" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleCaptions" data-slide-to="1"></li>
<li data-target="#carouselExampleCaptions" data-slide-to="2"></li>
</ol>
<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-target="#carouselExampleCaptions" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-target="#carouselExampleCaptions" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</button>
</div>
Crossfade
Eketsa .carousel-fade
ho carousel ea hau ho phelisa li-slide ka ho fifala ho e-na le li-slide. Ho ipapisitse le litaba tsa carousel ea hau (mohlala, li-slide tsa mongolo feela), u kanna oa batla ho kenyelletsa .bg-body
kapa CSS ea tloaelo ho .carousel-item
s bakeng sa ho putlama hantle.
<div id="carouselExampleFade" class="carousel slide carousel-fade" data-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-target="#carouselExampleFade" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-target="#carouselExampleFade" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</button>
</div>
.carousel-item
Nako ea motho ka mong
Kenya data-interval=""
ho a .carousel-item
ho fetola nako ea ho lieha lipakeng tsa ho palama baesekele ka bo eona ho ea nthong e latelang.
<div id="carouselExampleInterval" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active" data-interval="10000">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item" data-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-target="#carouselExampleInterval" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-target="#carouselExampleInterval" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</button>
</div>
Tlosa ho swiping ka ho ama
Li-carousels li tšehetsa ho swipella ka ho le letšehali/ ho le letona ho lisebelisoa tsa sekirini sa ho ama ho tsamaea lipakeng tsa li-slide. Sena se ka emisoa ho sebelisoa data-touch
tšobotsi. Mohlala o ka tlase le ona ha o kenyelle data-ride
tšobotsi mme o na data-interval="false"
le hoo ha o bapale.
<div id="carouselExampleControlsNoTouching" class="carousel slide" data-touch="false" data-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-target="#carouselExampleControlsNoTouching" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-target="#carouselExampleControlsNoTouching" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</button>
</div>
Tšebeliso
Ka litšobotsi tsa data
Sebelisa litšobotsi tsa data ho laola boemo ba carousel habonolo. data-slide
e amohela mantsoe a sehlooho prev
kapa next
, e fetolang boemo ba slide ho ipapisitse le boemo ba hona joale. Ntle le moo, sebelisa data-slide-to
ho fetisa index ea li-slide e tala ho carousel data-slide-to="2"
, e fetolang boemo ba li-slide ho index e itseng e qalang ka 0
.
Tšobotsi data-ride="carousel"
e sebelisoa ho tšoaea carousel e le e phelang ho qala ka palo ea maqephe. Haeba u sa sebelise data-ride="carousel"
ho qala carousel ea hau, u tlameha ho e qala ka bouena. E ke ke ea sebelisoa hammoho le (ho sa hlokahale le ho sa hlokahale) ho qalisoa ka ho hlaka ha JavaScript ea carousel e tšoanang.
Ka JavaScript
Letsetsa carousel ka letsoho ka:
$('.carousel').carousel()
Dikgetho
Likhetho li ka fetisoa ka lintlha tsa data kapa JavaScript. Bakeng sa litšobotsi tsa data, kenya lebitso la khetho ho data-
, joalo ka data-interval=""
.
Lebitso | Mofuta | Ea kamehla | Tlhaloso |
---|---|---|---|
karohano | palo | 5000 | Nako ea ho lieha pakeng tsa ho palama ntho ka bo eona. Haeba false , carousel e ke ke ea potoloha ka bo eona. |
keyboard | boolean | 'nete | Hore na carousel e lokela ho arabela liketsahalong tsa keyboard. |
kgefutsa | khoele | boolean | 'hover' | Ha e setetswe ho Lisebelisoa tse lumelletsoeng ho ama, ha li setiloe ho |
palama | khoele | bohata | E bapala carousel ka mor'a hore mosebelisi a potolohe ntho ea pele. Ha e setetswe ho 'carousel' , e bapala carousel e ntse e le teng. |
thatela | boolean | 'nete | Hore na carousel e lokela ho potoloha ka ho sa feleng kapa e eme ka thata. |
thetsa | boolean | 'nete | Hore na carousel e lokela ho ts'ehetsa litšebelisano tsa swipe ka ho le letšehali/le ho le letona ho lisebelisoa tsa sekirini sa ho ama. |
Mekhoa
Mekhoa ea Asynchronous le liphetoho
Mekhoa eohle ea API ha e- synchronous 'me e qala phetoho . Ba khutlela ho motho ea letselitseng hang ha phetoho e qala empa pele e fela . Ho feta moo, mohala oa mokhoa ho karolo ea phetoho o tla hlokomolohuoa .
Sheba litokomane tsa rona tsa JavaScript bakeng sa lintlha tse ling .
.carousel(options)
E qala carousel ka khetho ea boikhethelo object
ebe e qala ho palama lintho.
$('.carousel').carousel({
interval: 2000
})
.carousel('cycle')
E potoloha ka har'a lintho tsa carousel ho tloha ho le letšehali ho ea ho le letona.
.carousel('pause')
E emisa carousel ho palama baesekele ka har'a lintho.
.carousel(number)
E potoloha carousel ho foreime e itseng (0 e thehiloeng, e ts'oanang le lethathamo). E khutlela ho motho ea letselitseng pele ntho e lebisitsoeng e bontšoa (ke hore pele slid.bs.carousel
ketsahalo e etsahala).
.carousel('prev')
Lipotoloho ho ea nthong e fetileng. E khutlela ho moletsi pele ntho e fetileng e bontšoa (ke hore pele slid.bs.carousel
ketsahalo e etsahala).
.carousel('next')
Lipotoloho ho ea nthong e latelang. E kgutlela ho moletsi pele ntho e latelang e bontshwa (ke hore pele slid.bs.carousel
ketsahalo e etsahala).
.carousel('dispose')
E senya carousel ea element.
.carousel('nextWhenVisible')
Se ke oa potoloha carousel ho ea ho e latelang ha leqephe le sa bonahale kapa carousel kapa motsoali oa eona a sa bonahale. E kgutlela ho moletsi pele ntho e latelang e bontshwa (ke hore pele slid.bs.carousel
ketsahalo e etsahala).
.carousel('to')
E potoloha carousel ho foreime e itseng (0 e thehiloeng, e ts'oanang le lethathamo). E kgutlela ho moletsi pele ntho e latelang e bontshwa (ke hore pele slid.bs.carousel
ketsahalo e etsahala).
Liketsahalo
Sehlopha sa carousel sa Bootstrap se pepesa liketsahalo tse peli tsa ho hokahana le ts'ebetso ea carousel. Liketsahalo tsena ka bobeli li na le litšobotsi tse latelang:
direction
: Tsela eo carousel e thellang ho eona (ebang ke"left"
kapa"right"
).relatedTarget
: Karolo ea DOM e ntseng e theoleloa sebakeng e le eona ntho e sebetsang.from
: Lenane la ntho ea hajoaleto
: Lenane la ntho e latelang
Liketsahalo tsohle tsa carousel li thunngoa ho carousel ka boeona (ke hore ho <div class="carousel">
).
Mofuta oa Ketsahalo | Tlhaloso |
---|---|
slide.bs.carousel | Ketsahalo ena e tuka hang hang ha slide mokhoa oa mohlala o sebelisoa. |
slid.bs.carousel | Ketsahalo ena e thunngoa ha carousel e phethela phetoho ea eona ea li-slide. |
$('#myCarousel').on('slide.bs.carousel', function () {
// do something...
})
Fetola nako ea phetoho
Nako ea phetoho e .carousel-item
ka fetoloa ka mofuta oa $carousel-transition
Sass pele o hlophisa kapa mekhoa ea tloaelo haeba o sebelisa CSS e hlophisitsoeng. Haeba ho sebelisoa liphetoho tse ngata, etsa bonnete ba hore phetoho ea phetoho e hlalosoa pele (mohlala. transition: transform 2s ease, opacity .5s ease-out
).