Source

Carousel

He kiʻi kiʻi kiʻi no ka holo kaʻa ʻana ma waena o nā mea—nā kiʻi a i ʻole nā ​​paheʻe kikokikona—e like me ka carousel.

Pehea e hana ai

ʻO ka carousel kahi kiʻi kiʻiʻoniʻoni no ka holo kaʻa ʻana ma o ke ʻano o ka ʻike, i kūkulu ʻia me CSS 3D transforms a me kahi mea JavaScript. Hoʻohana ia me nā kiʻi, kikokikona, a i ʻole markup maʻamau. Loaʻa pū kekahi i ke kākoʻo no nā mana mua / aʻe a me nā hōʻailona.

Ma nā polokalamu kele pūnaewele kahi i kākoʻo ʻia ai ka API Visibility ʻAoʻao , e pale ka carousel i ka paheʻe ʻana ke ʻike ʻole ʻia ka ʻaoʻao pūnaewele e ka mea hoʻohana (e like me ka wā ʻaʻole hoʻohana ʻia ka ʻaoʻao polokalamu kele pūnaewele, hoʻemi ʻia ka puka aniani, etc.).

E ʻoluʻolu e hoʻomaopopo ʻaʻole kākoʻo ʻia nā carousels pūnana, a ʻaʻole kūlike nā carousels i nā kūlana hiki ke loaʻa.

ʻO ka hope, inā ʻoe e kūkulu nei i kā mākou JavaScript mai ke kumu, ponoutil.js ia .

Laʻana

ʻAʻole hana maʻamau nā Carousels i nā ana paheʻe. No laila, pono paha ʻoe e hoʻohana i nā pono hana hou a i ʻole nā ​​​​ʻano maʻamau i ka nui o ka ʻike. ʻOiai ke kākoʻo nei nā carousels i nā mana a me nā hōʻailona o mua/hope aku, ʻaʻole koi ʻia lākou. Hoʻohui a hoʻopilikino e like me kou manaʻo pono.

E hoʻonohonoho i kahi id kū hoʻokahi ma ka .carouselno nā mana koho, ʻoi aku ka nui inā hoʻohana ʻoe i nā carousels he nui ma ka ʻaoʻao hoʻokahi.

Paheʻe wale

Eia kahi carousel me nā paheʻe wale nō. E hoʻomaopopo i ka loaʻa ʻana o nā kiʻi carousel .d-blocka .img-fluidma luna o nā kiʻi carousel e pale ai i ka hoʻolikelike kiʻi paʻamau.

<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>

Me nā mana

Hoʻohui i nā mana mua a me nā mea hou aʻe:

<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>

Me nā hōʻailona

Hiki iā ʻoe ke hoʻohui i nā hōʻailona i ka carousel, me ka ʻaoʻao o nā mana.

<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>
Pono ka mea hana mua

Pono .activee hoʻohui ʻia ka papa i kekahi o nā paheʻe. A i ʻole, ʻaʻole ʻike ʻia ka carousel.

Me nā huaʻōlelo

Hoʻohui maʻalahi i nā huaʻōlelo i kāu mau paheʻe me ka .carousel-captionmea i loko o kekahi .carousel-item. Hiki iā lākou ke hūnā maʻalahi ma nā wahi nānā liʻiliʻi, e like me ka mea i hōʻike ʻia ma lalo nei, me nā pono hōʻike koho . Huna mua mākou iā lākou .d-noneme ka hoʻihoʻi ʻana iā lākou ma nā hāmeʻa liʻiliʻi me .d-md-block.

<div class="carousel-item">
  <img src="..." alt="...">
  <div class="carousel-caption d-none d-md-block">
    <h5>...</h5>
    <p>...</p>
  </div>
</div>

Hoʻohana

Ma o nā hiʻohiʻona ʻikepili

E hoʻohana i nā hiʻohiʻona ʻikepili e hoʻomalu maʻalahi i ke kūlana o ka carousel. data-slideʻae i nā huaʻōlelo a i prevʻole next, e hoʻololi i ke kūlana paheʻe e pili ana i kona kūlana i kēia manawa. ʻO kahi ʻē aʻe, e hoʻohana data-slide-toi ka hāʻawi ʻana i kahi papa kuhikuhi paheʻe maka i ka carousel data-slide-to="2", e hoʻololi i ke kūlana paheʻe i kahi kuhikuhi kikoʻī e hoʻomaka ana me 0.

Hoʻohana data-ride="carousel"ʻia ka ʻano e hōʻailona ai i kahi carousel ma ke ʻano he animating e hoʻomaka ana ma ka hoʻouka ʻana i ka ʻaoʻao. ʻAʻole hiki ke hoʻohana pū ʻia me (nui a pono ʻole) ka hoʻomaka mua ʻana o JavaScript o ka carousel like.

Ma o JavaScript

Kāhea lima ʻia ka carousel me:

$('.carousel').carousel()

Nā koho

Hiki ke hāʻawi ʻia nā koho ma o nā ʻikepili a i ʻole JavaScript. No nā ʻano ʻikepili, e hoʻopili i ka inoa koho i data-, e like me ka data-interval="".

inoa ʻAno Default wehewehe
waena helu 5000 ʻO ka nui o ka manawa e hoʻopaneʻe ai ma waena o ke kaʻa ʻakomi i kahi mea. Inā hoʻopunipuni, ʻaʻole e holo ʻokoʻa ka carousel.
keyboard boolean ʻoiaʻiʻo Inā paha e pane ka carousel i nā hanana keyboard.
hoʻomaha kaula | boolean "holo"

Inā hoʻonoho ʻia i "hover", hoʻomaha i ke kaʻa kaʻa o ka carousel mouseentera hoʻomaka hou i ke kaʻa kaʻa o ka carousel ma mouseleave. Inā hoʻonoho ʻia iā false, ʻaʻole e hoʻomaha ke kau ʻana ma luna o ka carousel.

Ma nā hāmeʻa hiki ke hoʻopā, ke hoʻonoho ʻia iā "hover", e hoʻomaha ke kaʻa uila touchend(ke pau ka mea hoʻohana i ka launa pū ʻana me ka carousel) no ʻelua manawa, ma mua o ka hoʻomaka ʻana. E hoʻomaopopo he hoʻohui kēia i ka hana ʻiole ma luna.

holo kaulahao wahahee Hoʻokani ʻauʻa i ka carousel ma hope o ka holo lima ʻana o ka mea hoʻohana i ka mea mua. Inā "carousel", ho'okani 'akomi i ka carousel ma ka hoouka.
kāʻei boolean ʻoiaʻiʻo Inā pono ke kaʻa kaʻa kaʻa kaʻa kaʻa a i ʻole ka paʻakikī.

Nā ʻano hana

Nā ʻano asynchronous a me nā hoʻololi

Asynchronous nā ala API āpau a hoʻomaka i kahi hoʻololi . Hoʻi lākou i ka mea kelepona i ka wā e hoʻomaka ai ka hoʻololi akā ma mua o ka pau ʻana . Eia kekahi, e nānā ʻole ʻia kahi ala e kāhea ai i kahi mea hoʻololi .

E ʻike i kā mākou palapala JavaScript no ka ʻike hou aku.

.carousel(options)

Hoʻomaka ka carousel me nā koho koho objecta hoʻomaka i ka holo kaʻa i nā mea.

$('.carousel').carousel({
  interval: 2000
})

.carousel('cycle')

Kaʻapuni i nā mea carousel mai ka hema a i ka ʻākau.

.carousel('pause')

Hoʻopau i ka carousel mai ka holo paikikala ma nā mea.

.carousel(number)

Hoʻololi i ka carousel i kahi kiʻi kikoʻī (ma muli o 0, e like me kahi array). E hoʻi i ka mea kelepona ma mua o ka hōʻike ʻia ʻana o ka mea i manaʻo ʻia (ʻo ia hoʻi ma mua o ka hiki ʻana o ka slid.bs.carouselhanana).

.carousel('prev')

Hoʻoholo i ka mea mua. Hoʻi i ka mea kelepona ma mua o ka hōʻike ʻia ʻana o ka mea mua (ʻo ia hoʻi ma mua o ka hiki ʻana o ka slid.bs.carouselhanana).

.carousel('next')

Hoʻoholo i ka mea aʻe. E hoʻi i ka mea kelepona ma mua o ka hōʻike ʻia ʻana o ka mea aʻe (ʻo ia hoʻi ma mua o ka hiki ʻana o ka slid.bs.carouselhanana).

.carousel('dispose')

Hoʻopau i ka carousel o kekahi mea.

Nā hanana

Hōʻike ka papa carousel o Bootstrap i ʻelua hanana no ka hoʻopili ʻana i ka hana carousel. Loaʻa i nā hanana ʻelua nā waiwai hou aʻe:

  • direction: ʻO ka ʻaoʻao e heʻe ana ka carousel (a i "left"ʻole "right").
  • relatedTarget: ʻO ka mea DOM e hoʻoneʻe ʻia ana ma ke ʻano he mea hana.
  • from: Ka papa kuhikuhi o ka mea o keia manawa
  • to: Ka papa kuhikuhi o ka mea aʻe

Hoʻopau ʻia nā hanana carousel a pau i ka carousel ponoʻī (ʻo ia hoʻi ma ka <div class="carousel">).

ʻAno Hanana wehewehe
slide.bs.carousel Hoʻopau koke ʻia kēia hanana i ka wā slidee kāhea ʻia ke ʻano hana.
slid.bs.carousel Hoʻopau ʻia kēia hanana ke hoʻopau ka carousel i kāna hoʻololi paheʻe.
$('#myCarousel').on('slide.bs.carousel', function () {
  // do something…
})