Source

Carousel

Chigawo cha chiwonetsero chazithunzi poyendetsa zinthu - zithunzi kapena masilayidi amawu - ngati karouse.

Momwe zimagwirira ntchito

Carousel ndi chiwonetsero chazithunzi chakuyenda panjinga zingapo, zomangidwa ndi zosintha za CSS 3D ndi JavaScript pang'ono. Zimagwira ntchito ndi zithunzi zingapo, zolemba, kapena zolembera makonda. Zimaphatikizansopo zothandizira zowongolera zam'mbuyo / zotsatila ndi zizindikiro.

M'masakatuli omwe Tsamba Lowonekera API limathandizidwa, carousel imapewa kutsetsereka pomwe tsamba lawebusayiti silikuwoneka kwa wogwiritsa ntchito (monga pomwe tsamba la msakatuli silikugwira ntchito, zenera la osatsegula limachepetsedwa, ndi zina).

Chonde dziwani kuti ma carousel okhala ndi zisa sagwiritsidwa ntchito, ndipo ma carousel nthawi zambiri satsatira miyezo yofikira.

Pomaliza, ngati mukupanga JavaScript yathu kuchokera kugwero, pamafunikautil.js .

Chitsanzo

Ma carousel samangosintha kukula kwa slide. Chifukwa chake, mungafunike kugwiritsa ntchito zina zowonjezera kapena masitayilo achikhalidwe kuti mukwaniritse kukula koyenera. Ngakhale ma carousel amathandizira maulamuliro am'mbuyomu/otsatira ndi zizindikiro, sizofunikira. Onjezani ndikusintha momwe mukufunira.

Kalasi .activeiyenera kuwonjezeredwa ku imodzi mwazithunzi apo ayi carousel sidzawoneka. Onetsetsaninso kuti mwakhazikitsa id yapadera pazowongolera zomwe .carouselmwasankha, makamaka ngati mukugwiritsa ntchito ma carousel angapo patsamba limodzi. Zinthu zowongolera ndi zowonetsera ziyenera kukhala ndi mawonekedwe data-target(kapena hrefmaulalo) omwe amafanana ndi id ya .carouselchinthucho.

Masiladi okha

Nayi kalasi yokhala ndi masiladi okha. Dziwani kupezeka kwa zithunzi .d-blockndi .w-100pa carousel kuti mupewe kusanja kwazithunzi zosasinthika.

<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=".../800x400?auto=yes&bg=777&fg=555&text=First slide" alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src=".../800x400?auto=yes&bg=666&fg=444&text=Second slide" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src=".../800x400?auto=yes&bg=555&fg=333&text=Third slide" alt="Third slide">
    </div>
  </div>
</div>

Ndi zowongolera

Kuwonjezera maulamuliro akale ndi otsatirawa:

<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=".../800x400?auto=yes&bg=777&fg=555&text=First slide" alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src=".../800x400?auto=yes&bg=666&fg=444&text=Second slide" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src=".../800x400?auto=yes&bg=555&fg=333&text=Third slide" 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>

Ndi zizindikiro

Mukhozanso kuwonjezera zizindikiro ku carousel, pambali pa maulamuliro, nawonso.

<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=".../800x400?auto=yes&bg=777&fg=555&text=First slide" alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src=".../800x400?auto=yes&bg=666&fg=444&text=Second slide" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src=".../800x400?auto=yes&bg=555&fg=333&text=Third slide" 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>

Ndi mawu ofotokozera

Onjezani mawu omasulira pamasilayidi anu mosavuta ndi .carousel-captionchinthu chomwe chili mkati mwa .carousel-item. Atha kubisika mosavuta pamawonekedwe ang'onoang'ono, monga momwe tawonetsera pansipa, ndi zida zowonetsera . Timawabisa poyamba ndi .d-nonekuwabweretsanso pazida zokhala ndi .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>

Crossfade

Onjezani .carousel-fadeku carousel yanu kuti muwongolere ma slide ndi kusintha kozilala m'malo mwa slide.

<div id="carouselExampleFade" class="carousel slide carousel-fade" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100" src=".../800x400?auto=yes&bg=777&fg=555&text=First slide" alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src=".../800x400?auto=yes&bg=666&fg=444&text=Second slide" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src=".../800x400?auto=yes&bg=555&fg=333&text=Third slide" alt="Third slide">
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleFade" 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="#carouselExampleFade" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

Kugwiritsa ntchito

Kudzera muzochita za data

Gwiritsani ntchito mawonekedwe a data kuti muwongolere malo a carousel mosavuta. data-slideimavomereza mawu osakira prevkapena next, omwe amasintha malo a slide mogwirizana ndi momwe alili. Kapenanso, gwiritsani ntchito data-slide-tokupatsira chithunzithunzi cha silayidi ku carousel data-slide-to="2", yomwe imasamutsa malo a slide kupita ku index inayake kuyambira ndi 0.

Makhalidwewa data-ride="carousel"amagwiritsidwa ntchito kuyika carousel ngati yosangalatsa kuyambira pamasamba. Sichingagwiritsidwe ntchito limodzi ndi (zosafunikira komanso zosafunikira) kutsegulira kwa JavaScript kwa carousel yomweyo.

Kudzera pa JavaScript

Imbani carousel pamanja ndi:

$('.carousel').carousel()

Zosankha

Zosankha zitha kuperekedwa kudzera pa data kapena JavaScript. Pamawonekedwe a data, yonjezerani dzina lachisankho ku data-, monga mu data-interval="".

Dzina Mtundu Zosasintha Kufotokozera
nthawi nambala 5000 Kuchuluka kwa nthawi yochedwetsa pakati pa kuyendetsa chinthu chokha. Ngati zabodza, carousel siizungulira yokha.
kiyibodi boolean zoona Kaya carousel ikuyenera kuchitapo kanthu pazochitika za kiyibodi.
kupuma chingwe | boolean "kuyenda"

Ngati "hover"ikonzedwa , imitsani kukwera njinga ya carousel mouseenterndikuyambanso kukwera njinga ya carousel pa mouseleave. Ngati falseitayikidwa , kuyimirira pamwamba pa carousel sikuyimitsa.

Pazida zoyatsidwa ndi kukhudza, zikakhazikitsidwa ku "hover", kupalasa njinga kudzayima touchend(wogwiritsa ntchito akamaliza kucheza ndi carousel) kwa magawo awiri, asanayambenso. Zindikirani kuti izi ndikuwonjezera pamakhalidwe omwe ali pamwambapa.

kukwera chingwe zabodza Amasewera okha carousel wogwiritsa ntchito atazungulira pamanja chinthu choyamba. Ngati "carousel", imasewera okha carousel atanyamula.
kulunga boolean zoona Kaya carousel iyenera kuzungulira mosalekeza kapena kuyima movutikira.

Njira

Asynchronous njira ndi kusintha

Njira zonse za API ndizosasinthika ndipo zimayamba kusintha . Amabwerera kwa woyimbayo atangoyamba kusintha koma asanathe . Kuonjezera apo, kuyitana kwa njira pa gawo losintha kudzanyalanyazidwa .

Onani zolemba zathu za JavaScript kuti mudziwe zambiri.

.carousel(options)

Imayambitsa carousel ndi zosankha zomwe mungasankhe objectndikuyamba kuyendetsa zinthu.

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

.carousel('cycle')

Amazungulira zinthu za carousel kuchokera kumanzere kupita kumanja.

.carousel('pause')

Imayimitsa carousel kuti isayendetse zinthu.

.carousel(number)

Azunguliza carousel ku chimango china (0 kutengera, ofanana ndi gulu). Amabwereranso kwa woyimbirayo chinthu chomwe mukufuna chisanasonyezedwe (ie zisanachitike slid.bs.carousel).

.carousel('prev')

Kuzungulira kwa chinthu cham'mbuyo. Imabwereranso kwa woyimbirayo chinthu cham'mbuyo chisanasonyezedwe (mwachitsanzo, slid.bs.carouselchochitikacho chisanachitike).

.carousel('next')

Kuzungulira ku chinthu chotsatira. Imabwereranso kwa woyimbirayo chinthu china chisanasonyezedwe (mwachitsanzo, slid.bs.carouselchochitikacho chisanachitike).

.carousel('dispose')

Kuwononga carousel ya element.

Zochitika

Kalasi ya carousel ya Bootstrap imawulula zochitika ziwiri zolumikizana ndi machitidwe a carousel. Zochitika zonsezi zili ndi zotsatirazi zowonjezera:

  • direction: Njira yomwe carousel ikutsetserekera (kaya "left"kapena "right").
  • relatedTarget: Chigawo cha DOM chomwe chikusunthidwa kuti chikhale chogwira ntchito.
  • from: Mndandanda wazinthu zamakono
  • to: Mlozera wa chinthu chotsatira

Zochitika zonse za carousel zimathamangitsidwa pa carousel yomwe (ie pa <div class="carousel">).

Mtundu wa Chochitika Kufotokozera
slide.bs.carousel Chochitika ichi chimayaka nthawi yomweyo slidenjira yachitsanzo ikugwiritsidwa ntchito.
slid.bs.carousel Chochitikachi chimathamangitsidwa pamene carousel yamaliza kusintha kwake kwa slide.
$('#myCarousel').on('slide.bs.carousel', function () {
  // do something…
})

Sinthani nthawi yosinthira

Nthawi yosinthira .carousel-itemimatha kusinthidwa ndikusintha kwa $carousel-transitionSass musanapange kapena masitayilo achikhalidwe ngati mukugwiritsa ntchito CSS yophatikizidwa. Ngati masinthidwe angapo agwiritsidwa ntchito, onetsetsani kuti masinthidwewo afotokozedwa poyamba (mwachitsanzo. transition: transform 2s ease, opacity .5s ease-out).