in English

Karosel

Slide jiracogo yɔrɔ min bɛ kɛ ka cycle kɛ fɛnw kɔnɔ—jaw walima sɛbɛnniw slidew—i n’a fɔ carousel.

A bɛ baara kɛ cogo min na

Carousel ye slideshow ye min bɛ kɛ ka cycling kɛ ka tɛmɛn kɔnɔkow kan, min jɔlen bɛ ni CSS 3D transforms ye ani JavaScript dɔɔnin. A bɛ baara kɛ ni jaw, sɛbɛnniw walima taamasiyɛnw ye minnu bɛ tugu ɲɔgɔn na. A fana bɛ dɛmɛ don kɔlɔsili tɛmɛnenw/nataw la ani taamasiyɛnw na.

Navigatɛri minnu na Page Visibility API bɛ dɛmɛ, carousel bɛna a yɛrɛ tanga sɛgɛn ma ni webpage tɛ ye baarakɛla fɛ (i n’a fɔ ni navigatɛri tab tɛ baara la, navigatɛri finɛtiri bɛ dɔgɔya, a ɲɔgɔnnaw).

Nin yɔrɔ in ka animation nɔ bɛ bɔ prefers-reduced-motionmedia ɲininkali de la. aw ye an ka sɔrɔli sɛbɛnw yɔrɔ lajɛ min bɛ lamaga dɔgɔyalen na .

Aw k’a dɔn ko nested carousels tɛ dɛmɛ, wa carousels caman tɛ bɛn sɔrɔli sariyaw ma.

A laban na, n’i b’an ka JavaScript jɔ ka bɔ source la, a bɛ wajibiyautil.js .

Misaliya

Carousels tɛ slide dimensions normalize u yɛrɛma. O cogo la, i bɛ se ka baara kɛ ni nafamafɛn wɛrɛw ye walima ka baara kɛ ni cogoyaw ye minnu bɛ kɛ ka kɛɲɛ ni i yɛrɛ sago ye walasa ka kunnafoniw bonya ka bɛn. Hali ni karoselw bɛ dɛmɛ don kɔrɔlenw/nataw ni taamasiyɛnw na, u tɛ wajibiya k’a jɛya. Aw bɛ dɔ fara a kan ani ka a kɛ ka kɛɲɛ ni aw yɛrɛ sago ye.

Kalanso .activeka kan ka fara slide dɔ kan n’o tɛ carousel tɛna ye. Aw ye aw jija fana ka fɛn kɛrɛnkɛrɛnnen dɔ sigi sen idkan .carouselfor optionnels controls, kɛrɛnkɛrɛnnenya la n’aw bɛ baara kɛ ni carousel caman ye ɲɛ kelen kan. Kontrɔli ni jiralan fɛnw ka kan ka kɛ ni fɛn dɔ data-targetye (walima hrefka ɲɛsin ɲɔgɔndanw ma) min bɛ bɛn fɛn idin ta .carouselma.

Slides dɔrɔn

Nin ye carousel ye ni slides dɔrɔn de ye. A kɔlɔsi ko .d-blockani .w-100bɛ carousel jaw kan walasa ka browser default image alignment bali.

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

Ni controles ye

Fàrali kan kɔrɔlenw ni nataw la. An bɛ ladilikan di ka baara kɛ ni <button>fɛnw ye, nka aw bɛ se ka baara kɛ ni <a>fɛnw ye fana ni 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>

Ni taamasiyɛnw ye

Aw bɛ se fana ka taamasiyɛnw fara carousel kan, ka fara controls kan, olu fana.

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

Ni sɛbɛnniw ye

aw bɛ sɛbɛnniw fara aw ka slayidiw kan nɔgɔya la ni .carousel-captionfɛn ye min bɛ fɛn o fɛn kɔnɔ .carousel-item. U bɛ se ka dogo nɔgɔya la filɛlikɛyɔrɔ fitininw kan, i n’a fɔ a jiralen bɛ cogo min na jukɔrɔ, ni jiracogo nafamaw ye minnu bɛ se ka sugandi . An b’u dogo a daminɛ na ni .d-nonek’u lasegin minɛn cɛmancɛw kan ni .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 ye

Aw bɛ fara .carousel-fadeaw ka carousel kan walasa ka slidew ɲɛnamaya ni fade transition ye slide nɔ na. Ka da i ka carousel kɔnɔkow kan (misali la, sɛbɛnni dɔrɔn slidew), i bɛ se ka .bg-bodyCSS custom dɔw fara .carousel-items kan walasa ka crossfading ɲuman sɔrɔ.

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

A bɛ fara a kan data-interval=""walasa .carousel-itemka waati hakɛ Changer ka waati latɛmɛ otomatiki bisikili ni fɛn nata cɛ.

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

Aw bɛ maga-maga-sɛgɛsɛgɛli bali

Carousels bɛ dɛmɛ don ka swiping kinin fɛ/numan fɛ touchscreen minɛnw kan walasa ka taa slidew ni ɲɔgɔn cɛ. O bɛ se ka bali ni data-touchfɛnsɛbɛnni ye. Misali min bɛ duguma o fana tɛ data-rideattribut (fɛnɲɛnɛma) Dòn a la wa a bɛ yen data-interval="false"o la a tɛ autoplay (autoplay) Kɛ.

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

Baarakɛcogo

Donanw ka fɛnɲɛnɛmaw fɛ

Baara kɛ ni data attributes ye walasa ka carousel jɔyɔrɔ kɔlɔsi nɔgɔya la. data-slidebɛ sɔn daɲɛ kolomaw ma prevwalima next, o min bɛ slide jɔyɔrɔ Changer ka kɛɲɛ n’a jɔyɔrɔ ye sisan. Ni o tɛ, baara kɛ ni data-slide-toka slide index raw tɛmɛ ka taa carousel data-slide-to="2", o bɛ slide jɔyɔrɔ wuli ka taa index kɛrɛnkɛrɛnnen dɔ la min bɛ daminɛ ni 0.

O data-ride="carousel"jogo bɛ Kɛ ka carousel dɔ taamaʃyɛn Kɛ i n'a fɔ animation (ɲɛnamaya) k'a Daminɛ ɲɛ doni na. N'i ma baara Kɛ data-ride="carousel"k'i ka carousel daminɛ, i yɛrɛ ka kan k'a daminɛ. A tɛ Se ka baara Kɛ ni (redundant ani unnecessary) JavaScript daminɛcogo jɛlen ye carousel kelen na.

JavaScript fɛ

Aw bɛ carousel wele ni bolo ye ni:

$('.carousel').carousel()

Sugandili minnu bɛ kɛ

Sugandili bɛ se ka tɛmɛ data attributes walima JavaScript fɛ. Donanw cogoyaw kama, aw bɛ sugandi tɔgɔ fara data-, i n’a fɔ a bɛ cogo min na data-interval="".

Tɔ̀gɔ Ka sɛbɛen masin na Fɔlɔ Cogojirali
cɛmancɛ nimɔrɔ 5000 ye Waati hakɛ min ka kan ka bila kɔfɛ fɛn dɔ bolicogo otomatiki la. Ni false, carousel tɛna cycle kɛ a yɛrɛma.
klaviyeti ye boolean ye sɛbɛ Ni carousel ka kan ka jaabi di klaviyeti ko kɛlenw ma.
ka jɔ juru | boolean ye 'hover' ye.

ni a bilalen don 'hover', a bɛ karɔsi ka cycle jɔli jɔ ani ka carousel mouseenterka cycle boli daminɛ kokura mouseleave. Ni a bilalen bɛ false, ka i yɛrɛ wuli karɔsi kan, o tɛna a jɔ.

Minɛn minnu bɛ se ka maga, n’u bilalen bɛ 'hover', wotoro bɛ jɔ touchend(ni baarakɛla ye jɛɲɔgɔnya kɛ ni karɔsi ye ka ban) waati fila kɔnɔ, sanni a ka segin a yɛrɛma. A kɔlɔsi ko nin bɛ fara sosɛti kɛcogo kan min fɔra sanfɛ.

ka boli gaari nkalon A bɛ carousel fɔ a yɛrɛma baarakɛla ka fɛn fɔlɔ cycle kɔfɛ a bolo fɛ. Ni a bilalen bɛ 'carousel', a bɛ carousel autoplay kɛ doni kan.
ka meleke boolean ye sɛbɛ Ni carousel ka kan ka to ka cycle kɛ walima ka jɔyɔrɔ gɛlɛnw sɔrɔ.
ka maga boolean ye sɛbɛ Ni carousel ka kan ka dɛmɛ don kininbolo/numanbolo fɛ swipe interactions kan touchscreen minɛnw kan.

Fɛɛrɛw

Fɛɛrɛ minnu tɛ kelen ye ani fɛn caman tigɛli

API fɛɛrɛw bɛɛ ye asynchrone ye ani ka tɛmɛsira dɔ daminɛ . u bɛ segin welebaga ma ni wuli daminɛna dɔrɔn nka sanni a ka ban . Ka fara o kan, fɛɛrɛ weleli min bɛ kɛ tɛmɛsira yɔrɔ dɔ kan, o bɛna jate .

aw ye an ka JavaScript sɛbɛnw lajɛ walasa ka kunnafoni wɛrɛw sɔrɔ .

.carousel(options)

A bɛ carousel daminɛ ni options options ye objectani ka cycle daminɛ fɛnw fɛ.

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

.carousel('cycle')

A bɛ cycle kɛ carousel fɛnw kɔnɔ ka bɔ numan fɛ ka taa kinin fɛ.

.carousel('pause')

A bɛ carousel bali ka boli ka tɛmɛ fɛnw fɛ.

.carousel(number)

A bɛ carousel cycle kɛ ka taa frame kɛrɛnkɛrɛnnen dɔ la (0 basigilen, a bɛ tali kɛ array dɔ la). A bɛ segin welebaga ma sanni laɲinifɛn ka jira (o kɔrɔ ye ko sanni ko slid.bs.carouselin ka kɛ).

.carousel('prev')

Sikiliw bɛ taa fɛn tɛmɛnen na. A bɛ segin welebaga ma sanni fɛn tɛmɛnen ka jira (o kɔrɔ ye ko sanni ko slid.bs.carouselin ka kɛ).

.carousel('next')

Sikiliw bɛ taa fɛn nata la. A bɛ segin welebaga ma sanni fɛn nata ka jira (o kɔrɔ ye ko sanni ko slid.bs.carouselin ka kɛ).

.carousel('dispose')

A bɛ element dɔ ka carousel tiɲɛ.

.carousel('nextWhenVisible')

Aw kana carousel cycle kɛ ka taa next ni ɲɛ tɛ ye walima carousel walima a bangebaga tɛ ye. A bɛ segin welebaga ma sanni fɛn nata ka jira (o kɔrɔ ye ko sanni ko slid.bs.carouselin ka kɛ).

.carousel('to')

A bɛ carousel cycle kɛ ka taa frame kɛrɛnkɛrɛnnen dɔ la (0 basigilen, a bɛ tali kɛ array dɔ la). A bɛ segin welebaga ma sanni fɛn nata ka jira (o kɔrɔ ye ko sanni ko slid.bs.carouselin ka kɛ).

Ko minnu kɛra

Bootstrap ka carousel kalan bɛ ko fila jira ka ɲɛsin hooking ka carousel baarakɛcogo ma. O ko fla bɛɛ bɛ ni nin nafa wɛrɛw ye:

  • direction: Karɔsi bɛ sɛgɛn sira min fɛ (o "left"walima "right").
  • relatedTarget: DOM yɔrɔ min bɛ ka sɛgɛn ka don a nɔ na i n’a fɔ fɛn min bɛ baara kɛ.
  • from: Fɛn min bɛ sen na sisan, o index (index) ye
  • to: Fɛn nata index (index) ye

Karosel ko kɛlenw bɛɛ bɛ ci karɔsi yɛrɛ la (o kɔrɔ ye ko <div class="carousel">).

Ko kɛlen suguya Cogojirali
slide.bs.karosel O ko in bɛ tasuma Bɔ o yɔrɔnin bɛɛ ni slidemisali fɛɛrɛ in Weele.
slid.bs.karɔsi ye O ko in bɛ Fɔ ni karɔsili ye a ka slide transition (slide) tigɛli dafa.
$('#myCarousel').on('slide.bs.carousel', function () {
  // do something...
})

Yɛlɛma donna tɛmɛsira kuntaala kan

Tɛmɛsira waati bɛ .carousel-itemse ka Changé ni $carousel-transitionSass variable ye ka sɔrɔ ka compiling walima custom styles kɛ ni i bɛ baara kɛ ni compilé CSS ye. Ni bεnkan caman bε Kε, i k’a lajɛ ni bεnkansεbεn bε ɲɛfɔ fɔlɔ (misali la transition: transform 2s ease, opacity .5s ease-out).