in English

Carousel

Igice cya sisitemu yo gusiganwa ku magare binyuze mu bintu - amashusho cyangwa amashusho yinyandiko - nka karuseli.

Uburyo ikora

Carousel ni slide yo gusiganwa ku magare binyuze mu ruhererekane rw'ibirimo, yubatswe na CSS 3D ihindura hamwe na JavaScript. Ikorana nuruhererekane rwamashusho, inyandiko, cyangwa ikimenyetso cyihariye. Harimo kandi inkunga kubanza / ubutaha kugenzura n'ibipimo.

Mucukumbuzi aho Page Visibility API ishyigikiwe, karuseli izirinda kunyerera mugihe urubuga rutagaragara kubakoresha (nkigihe iyo tab ya mushakisha idakora, idirishya rya mushakisha riba ryaragabanutse, nibindi).

Ingaruka ya animasiyo yibi bice biterwa prefers-reduced-motionnibibazo byitangazamakuru. Reba igice cyagabanijwe cyicyiciro cyibisobanuro byacu .

Nyamuneka umenye ko karuseli yatewe idashyigikiwe, kandi karuseli muri rusange ntabwo yujuje ubuziranenge bwo kugerwaho.

Ubwanyuma, niba wubaka JavaScript yacu kuva isoko, birasabautil.js .

Urugero

Carousels ntabwo ihita isanzwe ibipimo bya slide. Nkibyo, urashobora gukenera gukoresha ibikorwa byingirakamaro cyangwa uburyo bwihariye kugirango ubone ubunini bukwiye. Mugihe karuseli ishyigikira ibyabanje / ubutaha kugenzura n'ibipimo, ntabwo bisabwa neza. Ongeraho kandi uhindure uko ubishaka.

Icyiciro .activegikeneye kongerwaho kamwe mumashusho ubundi karuseli ntizagaragara. Wemeze kandi gushiraho umwihariko idkuri .carouselkugenzura kubushake, cyane cyane niba ukoresha karuseli nyinshi kurupapuro rumwe. Kugenzura no kwerekana ibipimo bigomba kugira data-targetikiranga (cyangwa hrefkubihuza) bihuye idnibintu .carousel.

Igice gusa

Hano karuseli ifite amashusho gusa. Reba ahari ibishusho bya .d-blockkaruseli .w-100kugirango wirinde gushakisha amashusho adasanzwe.

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

Nubugenzuzi

Ongeraho mubibanziriza nubutaha. Turasaba gukoresha <button>ibintu, ariko urashobora kandi gukoresha <a>ibintu hamwe 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>

Hamwe n'ibipimo

Urashobora kandi kongeramo ibipimo kuri karuseli, hamwe nubugenzuzi, nabwo.

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

Hamwe n'ibisobanuro

Ongeraho ibisobanuro kuri slide yawe byoroshye hamwe .carousel-captionnibintu muri byose .carousel-item. Birashobora guhishwa byoroshye kubireba bito, nkuko bigaragara hano hepfo, hamwe nibikorwa byingirakamaro . Turabahisha ubanza hamwe .d-noneno kubagarura kubikoresho biciriritse hamwe na .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>

Kwambukiranya

Ongera .carousel-fadekuri karuseli yawe kugirango ushushanye amashusho hamwe ninzibacyuho yazimye aho kuba slide. Ukurikije ibikubiyemo bya karuseli (urugero, inyandiko yerekana gusa), urashobora kongeramo .bg-bodycyangwa CSS yihariye kuri .carousel-items kugirango uhuze neza.

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

Ongeraho data-interval=""kuri a .carousel-itemkugirango uhindure igihe cyo gutinda hagati yo gusiganwa ku magare ku kintu gikurikira.

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

Hagarika gukorakora

Carousels ishyigikira guhanagura ibumoso / iburyo ku bikoresho bya ecran ya ecran kugirango yimuke hagati ya slide. Ibi birashobora guhagarikwa ukoresheje data-touchikiranga. Urugero rukurikira narwo ntirurimo data-rideikiranga kandi rufite data-interval="false"kugirango rudakora 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>

Ikoreshwa

Binyuze mu biranga amakuru

Koresha ibiranga amakuru kugirango ugenzure byoroshye umwanya wa karuseli. data-slideyemera ijambo ryibanze prevcyangwa next, rihindura umwanya uhagaze ugereranije nubu. Ubundi, koresha data-slide-tokugirango unyuze kumurongo wibanze kuri karuseli data-slide-to="2", ihinduranya umwanya kumwanya runaka utangirana na 0.

Ikiranga data-ride="carousel"gikoreshwa mukuranga karuseli nka animasiyo itangirira kurupapuro. Niba udakoresha data-ride="carousel"gutangiza karuseli yawe, ugomba kuyitangiza wenyine. Ntishobora gukoreshwa ifatanije na (kurenza kandi bitari ngombwa) JavaScript itangizwa ya karuseli imwe.

Binyuze kuri JavaScript

Hamagara karuseli intoki hamwe na:

$('.carousel').carousel()

Amahitamo

Amahitamo arashobora kunyuzwa kumurongo wamakuru cyangwa JavaScript. Kubiranga Ibyatanzwe, Ongeraho Ihitamo Izina Kuri data-, Nka Muri data-interval="".

Izina Andika Mburabuzi Ibisobanuro
intera umubare 5000 Ingano yigihe cyo gutinda hagati yizunguruka yikintu. Niba false, karuseli ntabwo izahita izunguruka.
Mwandikisho boolean ni ukuri Niba karuseli igomba kwitwara kubyabaye kuri clavier.
hagarara umugozi | boolean 'hover'

Niba byashyizweho 'hover', ihagarika amagare ya karuseli mouseenterhanyuma ikomeza gusiganwa ku magare ya karuseli kuri mouseleave. Niba byashyizweho false, kugendagenda hejuru ya karuseli ntibizahagarara.

Ku bikoresho bifasha gukoraho, mugihe byashizweho 'hover', gusiganwa ku magare bizahagarara touchend(igihe umukoresha arangije gukorana na karuseli) intera ebyiri, mbere yo guhita ikomeza. Menya ko ibi byiyongera kumyitwarire yimbeba yavuzwe haruguru.

kugendera umugozi ibinyoma Autoplays karuseli nyuma yumukoresha intoki azunguruka ikintu cya mbere. Niba byashyizweho 'carousel', autoplays karuseli kumuzigo.
gupfunyika boolean ni ukuri Niba karuseli igomba kuzunguruka ubudahwema cyangwa kugira guhagarara gukomeye.
gukoraho boolean ni ukuri Niba karuseli igomba gushyigikira ibumoso / iburyo bwo guhanagura ibikoresho bya ecran ya ecran.

Uburyo

Uburyo butajegajega ninzibacyuho

Inzira zose za API ntizihuza kandi zitangira inzibacyuho . Basubira kumuhamagara mugihe inzibacyuho itangiye ariko itararangira . Mubyongeyeho, uburyo bwo guhamagarira ibice byinzibacyuho bizirengagizwa .

Reba inyandiko zacu za JavaScript kubindi bisobanuro .

.carousel(options)

Itangiza karuseli hamwe nuburyo bwo guhitamo objecthanyuma igatangira gusiganwa ku magare binyuze mubintu.

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

.carousel('cycle')

Amagare anyuze muri karuseli kuva ibumoso ugana iburyo.

.carousel('pause')

Hagarika karuseli gusiganwa ku magare binyuze mu bintu.

.carousel(number)

Kuzenguruka karuseli kumurongo runaka (0 ishingiye, isa na array). Garuka kumuhamagara mbere yuko intego yerekanwe (ni ukuvuga mbere yuko slid.bs.carouselibyabaye biba).

.carousel('prev')

Amagare ku kintu kibanziriza iki. Garuka kumuhamagara mbere yikintu cyabanjirije cyerekanwe (ni ukuvuga mbere yuko slid.bs.carouselibyabaye biba).

.carousel('next')

Amagare ku kintu gikurikira. Garuka kumuhamagara mbere yikintu gikurikira cyerekanwe (ni ukuvuga mbere yuko slid.bs.carouselibyabaye biba).

.carousel('dispose')

Gusenya ikintu cya karuseli.

.carousel('nextWhenVisible')

Ntuzunguruke karuseli kurikurikira mugihe page itagaragara cyangwa karuseli cyangwa umubyeyi wacyo ntabwo bigaragara. Garuka kumuhamagara mbere yikintu gikurikira cyerekanwe (ni ukuvuga mbere yuko slid.bs.carouselibyabaye biba).

.carousel('to')

Kuzenguruka karuseli kumurongo runaka (0 ishingiye, isa na array). Garuka kumuhamagara mbere yikintu gikurikira cyerekanwe (ni ukuvuga mbere yuko slid.bs.carouselibyabaye biba).

Ibyabaye

Bootstrap ya karuseli yerekana ibintu bibiri byo guhuza imikorere ya karuseli. Ibyabaye byombi bifite imitungo yinyongera ikurikira:

  • direction: Icyerekezo karuseli iranyerera (haba "left"cyangwa "right").
  • relatedTarget: Ikintu cya DOM kirimo kunyerera ahantu nkikintu gikora.
  • from: Ironderero ryikintu kiriho
  • to: Ironderero ryikintu gikurikira

Ibintu byose bya karuseli birasa kuri karuseli ubwayo (ni ukuvuga kuri <div class="carousel">).

Ubwoko bwibyabaye Ibisobanuro
slide.bs.carousel Ibirori birasa ako kanya mugihe slideurugero rwakoreshejwe.
slide.bs.carousel Ibirori birukanwa mugihe karuseli yarangije kunyerera.
$('#myCarousel').on('slide.bs.carousel', function () {
  // do something...
})

Hindura igihe cyinzibacyuho

Igihe cyinzibacyuho .carousel-itemgishobora guhinduka hamwe na $carousel-transitionSass ihinduka mbere yo gukusanya cyangwa uburyo bwihariye niba ukoresha CSS yakozwe. Niba inzibacyuho nyinshi zashyizwe mu bikorwa, menya neza ko impinduka zasobanuwe mbere (urugero. transition: transform 2s ease, opacity .5s ease-out)