in English

Carousel

Ib qho slideshow tivthaiv rau kev caij tsheb kauj vab los ntawm cov ntsiab lus-cov duab lossis cov ntawv swb-zoo li lub voj voog.

Nws ua haujlwm li cas

Lub carousel yog slideshow rau cycling los ntawm ib tug series ntawm cov ntsiab lus, ua nrog CSS 3D transforms thiab me ntsis ntawm JavaScript. Nws ua haujlwm nrog cov duab, ntawv nyeem, lossis kev cai cim. Nws kuj suav nrog kev txhawb nqa rau yav dhau los / tom ntej tswj thiab ntsuas.

Hauv cov browsers uas qhov Page Visibility API tau txais kev txhawb nqa, lub carousel yuav zam zawv zawg thaum lub vev xaib tsis pom rau tus neeg siv (xws li thaum browser tab tsis ua haujlwm, qhov browser qhov rai raug txo qis, thiab lwm yam).

Cov nyhuv animation ntawm cov khoom siv no yog nyob ntawm cov prefers-reduced-motionlus nug xov xwm. Saib qhov txo qis ntawm peb cov ntaub ntawv nkag mus tau .

Thov nco ntsoov tias cov carousels nested tsis tau txais kev txhawb nqa, thiab carousels feem ntau tsis ua raws li cov qauv kev siv tau.

Thaum kawg, yog tias koj tab tom tsim peb JavaScript los ntawm qhov chaw, nws xav tauutil.js .

Piv txwv

Carousels tsis cia li normalize swb qhov ntev. Yog li ntawd, tej zaum koj yuav tau siv cov khoom siv ntxiv lossis cov qauv kev cai kom haum rau cov ntsiab lus loj. Thaum carousels txhawb nqa yav dhau los / tom ntej tswj thiab ntsuas, lawv tsis xav tau meej. Ntxiv thiab kho raws li koj pom haum.

Cov .activechav kawm yuav tsum tau ntxiv rau ib qho ntawm cov swb txwv tsis pub lub carousel yuav tsis pom. Tsis tas li yuav tsum tau teem caij tshwj xeeb idrau kev .carouselxaiv tswj, tshwj xeeb tshaj yog tias koj siv ntau lub carousels ntawm ib nplooj ntawv. Kev tswj thiab ntsuas cov ntsiab lus yuav tsum muaj tus data-targetcwj pwm (lossis hrefrau kev sib txuas) uas phim idlub .carouselntsiab lus.

Slides nkaus xwb

Ntawm no yog ib tug carousel nrog slides xwb. Nco ntsoov lub xub ntiag ntawm .d-blockthiab .w-100ntawm cov duab carousel los tiv thaiv qhov browser default duab sib dhos.

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

Nrog tswj

Ntxiv rau cov kev tswj yav dhau los thiab tom ntej. Peb pom zoo kom siv <button>cov khoom, tab sis koj tuaj yeem siv <a>cov ntsiab lus nrog 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>

Nrog ntsuas

Koj tuaj yeem ntxiv cov ntsuas rau lub carousel, nrog rau cov tswj, ib yam nkaus.

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

Nrog cov ntawv sau

Ntxiv cov ntawv sau rau koj cov slides yooj yim nrog cov .carousel-captionkhoom hauv ib qho twg .carousel-item. Lawv tuaj yeem muab zais tau yooj yim ntawm cov chaw saib me me, raws li qhia hauv qab no, nrog rau kev xaiv cov khoom siv hluav taws xob . Peb zais lawv thawj zaug nrog .d-nonethiab coj lawv rov qab rau ntawm cov khoom siv nruab nrab nrog .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

Ntxiv .carousel-faderau koj lub carousel rau animate slides nrog ib tug ploj mus hloov tsis yog ib tug swb. Nyob ntawm koj cov ntsiab lus carousel (xws li, ntawv tsuas yog slides), tej zaum koj yuav xav ntxiv .bg-bodylossis qee qhov kev cai CSS rau .carousel-items kom raug crossfading.

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

Ntxiv data-interval=""rau ib qho .carousel-itemlos hloov lub sijhawm ncua ntawm kev caij tsheb kauj vab mus rau yam khoom tom ntej.

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

Disable kov swiping

Carousels txhawb swiping sab laug / sab xis ntawm touchscreen li txav ntawm cov swb. Qhov no tuaj yeem cuam tshuam nrog tus data-touchcwj pwm. Cov piv txwv hauv qab no kuj tsis suav nrog tus data-ridecwj pwm thiab muaj data-interval="false"yog li nws tsis autoplay.

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

Kev siv

Los ntawm cov ntaub ntawv attributes

Siv cov ntaub ntawv cwj pwm kom yooj yim tswj txoj hauj lwm ntawm lub carousel. data-slidelees txais cov lus tseem ceeb prevlossis next, uas hloov txoj haujlwm swb txheeb ze rau nws txoj haujlwm tam sim no. Xwb, siv data-slide-tokom dhau qhov ntsuas qhov ntsuas tsis sib haum mus rau lub carousel data-slide-to="2", uas hloov txoj haujlwm swb mus rau qhov ntsuas tshwj xeeb pib nrog 0.

Tus data-ride="carousel"cwj pwm yog siv los khij lub carousel li animating pib ntawm nplooj ntawv load. Yog tias koj tsis siv data-ride="carousel"los pib koj lub carousel, koj yuav tsum pib nws tus kheej. Nws tsis tuaj yeem siv ua ke nrog (rov ua dua thiab tsis tsim nyog) qhia meej JavaScript pib ntawm tib lub carousel.

Ntawm JavaScript

Hu rau carousel manually nrog:

$('.carousel').carousel()

Kev xaiv

Cov kev xaiv tuaj yeem dhau los ntawm cov ntaub ntawv tus cwj pwm lossis JavaScript. Rau cov ntaub ntawv tus cwj pwm, ntxiv rau qhov kev xaiv npe rau data-, xws li hauv data-interval="".

Lub npe Hom Default Kev piav qhia
lub sijhawm tus lej 5000 Lub sijhawm ncua sijhawm ntawm kev caij tsheb kauj vab ib yam khoom. Yog hais tias false, carousel yuav tsis cia li voj voog.
keyboard boolean muaj tseeb Seb lub carousel yuav tsum teb rau cov xwm txheej keyboard.
nres hlua | boolean 'hover'

Yog tias tau teeb tsa 'hover', nres lub caij tsheb kauj vab ntawm lub carousel rau mouseenterthiab rov pib caij tsheb kauj vab ntawm lub carousel rau mouseleave. Yog tias teem rau false, hovering hla lub carousel yuav tsis nres nws.

Ntawm cov khoom siv kov, thaum teem rau 'hover', kev caij tsheb kauj vab yuav nres rau touchend(thaum tus neeg siv ua tiav kev cuam tshuam nrog lub carousel) rau ob lub sijhawm, ua ntej yuav rov pib dua. Nco ntsoov tias qhov no yog ntxiv rau tus cwj pwm nas saum toj no.

caij txoj hlua cuav Autoplays lub carousel tom qab tus neeg siv manually cycles thawj yam khoom. Yog teem rau 'carousel', autoplays lub carousel ntawm load.
qhwv boolean muaj tseeb Txawm hais tias lub carousel yuav tsum tsis tu ncua los yog muaj zog nres.
kov boolean muaj tseeb Seb lub carousel yuav tsum txhawb sab laug / sab xis los so kev sib cuam tshuam ntawm cov khoom siv touchscreen.

Cov txheej txheem

Asynchronous txoj kev thiab kev hloov

Txhua txoj kev API yog asynchronous thiab pib hloov pauv . Lawv rov qab mus rau tus neeg hu xov tooj sai li sai tau thaum qhov kev hloov pauv pib tab sis ua ntej nws xaus . Tsis tas li ntawd, ib txoj kev hu rau ib qho kev hloov pauv yuav raug tsis quav ntsej .

Saib peb cov ntaub ntawv JavaScript kom paub ntau ntxiv .

.carousel(options)

Pib lub carousel nrog ib qho kev xaiv xaiv objectthiab pib caij tsheb kauj vab los ntawm cov khoom.

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

.carousel('cycle')

Cycles los ntawm cov khoom carousel ntawm sab laug mus rau sab xis.

.carousel('pause')

Nres lub carousel los ntawm kev caij tsheb kauj vab los ntawm cov khoom.

.carousel(number)

Cycles lub carousel rau ib lub thav duab tshwj xeeb (0 raws, zoo ib yam li ib qho array). Rov qab mus rau tus neeg hu ua ntej lub hom phiaj khoom tau tshwm sim (piv txwv li ua ntej qhov slid.bs.carouselxwm txheej tshwm sim).

.carousel('prev')

Lub voj voog mus rau qhov khoom dhau los. Rov qab mus rau tus neeg hu ua ntej qhov khoom dhau los tau tshwm sim (piv txwv li ua ntej qhov slid.bs.carouselxwm txheej tshwm sim).

.carousel('next')

Cycles mus rau yam khoom tom ntej. Rov qab mus rau tus neeg hu ua ntej cov khoom tom ntej tau tshwm sim (piv txwv li ua ntej qhov slid.bs.carouselxwm txheej tshwm sim).

.carousel('dispose')

Ua kom lub ntsiab ntawm lub carousel.

.carousel('nextWhenVisible')

Tsis txhob tig lub voj voog mus rau tom ntej thaum nplooj ntawv tsis pom lossis lub carousel lossis nws niam nws txiv tsis pom. Rov qab mus rau tus neeg hu ua ntej cov khoom tom ntej tau tshwm sim (piv txwv li ua ntej qhov slid.bs.carouselxwm txheej tshwm sim).

.carousel('to')

Cycles lub carousel rau ib lub thav duab tshwj xeeb (0 raws, zoo ib yam li ib qho array). Rov qab mus rau tus neeg hu ua ntej cov khoom tom ntej tau tshwm sim (piv txwv li ua ntej qhov slid.bs.carouselxwm txheej tshwm sim).

Cov xwm txheej

Bootstrap's carousel class exposes ob txheej xwm rau hooking rau hauv carousel functionality. Ob qho xwm txheej muaj cov khoom nram qab no ntxiv:

  • direction: Cov kev taw qhia uas lub carousel zawv zawg (txawm "left"los yog "right").
  • relatedTarget: Lub caij DOM uas tau swb rau hauv qhov chaw ua cov khoom nquag.
  • from: Qhov Performance index ntawm cov khoom tam sim no
  • to: Qhov Performance index ntawm cov khoom tom ntej

Tag nrho cov xwm txheej carousel raug rho tawm haujlwm ntawm lub carousel nws tus kheej (piv txwv li ntawm <div class="carousel">).

Hom xwm txheej Kev piav qhia
swb.bs.carousel Qhov xwm txheej no tua hluav taws tam sim ntawd thaum tus slidetxheej txheem piv txwv raug hu.
swb.bs.carousel Qhov kev tshwm sim no raug rho tawm haujlwm thaum lub carousel tau ua tiav nws txoj kev hloov pauv.
$('#myCarousel').on('slide.bs.carousel', function () {
  // do something...
})

Hloov lub sijhawm hloov pauv

Lub sijhawm hloov pauv ntawm .carousel-itemtuaj yeem hloov pauv nrog $carousel-transitionSass hloov pauv ua ntej sau lossis cov qauv kev cai yog tias koj siv CSS suav nrog. Yog tias siv ntau qhov kev hloov pauv, xyuas kom meej tias qhov kev hloov pauv hloov tau txhais ua ntej (xws li. transition: transform 2s ease, opacity .5s ease-out).