Esasy mazmuna geçiň Docs nawigasiýasyna geçiň
in English

Deňiz we bellikler

“Bootstrap” -yň goşulan nawigasiýa komponentlerini nädip ulanmalydygy barada resminamalar we mysallar.

Base nav

.nav“Bootstrap” -da bar bolan nawigasiýa, esasy synpdan işjeň we maýyp ýagdaýlara çenli umumy bellikleri we stilleri paýlaşýar . Her stiliň arasynda geçmek üçin üýtgediji synplary çalyşyň.

Esasy .navkomponent flexbox bilen gurlup, ähli nawigasiýa komponentlerini gurmak üçin berk binýady üpjün edýär. Onda käbir stil ýazgylary (sanawlar bilen işlemek üçin), has uly urlan ýerler üçin käbir baglanyşyk paddingleri we esasy maýyp stilleri bar.

Esasy .navkomponent haýsydyr bir ýagdaýy öz içine almaýar .active. Aşakdaky mysallar, esasanam bu aýratyn synpyň hiç hili ýörite stil döretmeýändigini görkezmek üçin synpy öz içine alýar.

Işjeň ýagdaýy kömekçi tehnologiýalara ýetirmek üçin aria-currentatributdan peýdalanyň - häzirki sahypa ýa -da toplumdaky häzirki element üçin pagebahany ulanyň.true

<ul class="nav">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

Sapaklar hemme ýerde ulanylýar, şonuň üçin belligiňiz gaty çeýe bolup biler. Harytlaryňyzyň tertibi möhüm bolsa, <ul>ýokardaky ýaly s ulanyň ýa-da bir element bilen özüňizi aýlaň. Ulanylyşy sebäpli , nav baglanyşyklary nav elementleri ýaly hereket edýär, ýöne goşmaça bellik bolmazdan.<ol><nav>.navdisplay: flex

<nav class="nav">
  <a class="nav-link active" aria-current="page" href="#">Active</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</nav>

Elýeterli stiller

S komponentiniň stilini .navüýtgedijiler we kömekçi enjamlar bilen üýtgediň. Zerur bolanda garyşdyryň we deňeşdiriň ýa-da özüňiz guruň.

Gorizontal deňleşdirme

“Navbox” -yň gorizontal deňleşmesini “ flexbox” enjamlary bilen üýtgediň . Düzgüne görä, deňiz güýçleri çep hatara düzülendir, ýöne olary aňsatlyk bilen merkeze ýa-da sag tarapa üýtgedip bilersiňiz.

Merkezde .justify-content-center:

<ul class="nav justify-content-center">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

Sag bilen deňleşdirilen .justify-content-end:

<ul class="nav justify-content-end">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

Dik

Utgaşma bilen flex elementiň ugruny üýtgedip, nawigasiýaňyzy düzüň .flex-column. Olary käbir görnüşlerde ýerleşdirmeli, ýöne beýlekiler däl? Duýgur wersiýalary ulanyň (mysal üçin .flex-sm-column).

<ul class="nav flex-column">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

Hemişe bolşy ýaly, wertikal nawigasiýa <ul>s bolmasa-da mümkindir.

<nav class="nav flex-column">
  <a class="nav-link active" aria-current="page" href="#">Active</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</nav>

Salgylar

Esasy deňizden ýokardan alýar we goýlan .nav-tabsinterfeýs döretmek üçin synpy goşýar. JavaScript pluginimiz bilen tablisa sebitlerini döretmek üçin ulanyň .

<ul class="nav nav-tabs">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

Dermanlar

Şol bir HTML alyň, ýöne .nav-pillsýerine ulanyň:

<ul class="nav nav-pills">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

Doldur we akla

.navMazmunyňyzy iki üýtgediji synpyň biriniň elýeterli giňligini giňeltmäge mejbur ediň . Bar bolan ýerleri proporsional taýdan doldurmak üçin .nav-itemulanyň .nav-fill. Horhli gorizontal giňişligiň eýeleýändigine üns beriň, ýöne her bir deňiz elementiniň giňligi birmeňzeş däldir.

<ul class="nav nav-pills nav-fill">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Much longer nav link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

<nav>Esasy nawigasiýa ulanylanda, .nav-itemdiňe .nav-linkstil <a>elementleri üçin zerur bolany üçin arkaýyn goýup bilersiňiz.

<nav class="nav nav-pills nav-fill">
  <a class="nav-link active" aria-current="page" href="#">Active</a>
  <a class="nav-link" href="#">Much longer nav link</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</nav>

Deň giňlikdäki elementler üçin ulanyň .nav-justified. Horhli gorizontal giňişlik deňiz baglanyşyklary tarapyndan eýelener, ýöne .nav-fillýokardakylardan tapawutlylykda her deňiz elementi birmeňzeş giňlikde bolar.

<ul class="nav nav-pills nav-justified">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Much longer nav link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

Esasy nawigasiýa .nav-fillulanmak mysalyna meňzeýär .<nav>

<nav class="nav nav-pills nav-justified">
  <a class="nav-link active" aria-current="page" href="#">Active</a>
  <a class="nav-link" href="#">Much longer nav link</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</nav>

Flex kömekçi enjamlar bilen işlemek

Size jogap beriji üýtgeşiklikler gerek bolsa, flexbox kömekçi enjamlarynyň bir toparyny ulanmagy göz öňünde tutuň . Has köp sözli bolsa-da, bu kömekçi enjamlar jogap beriş nokatlarynda has uly özleşdirme hödürleýär. Aşakdaky mysalda, deňiz ýolumyz iň pes nokada ýerleşdiriler, soňra kiçi nokatdan başlap elýeterli giňligi doldurýan keseligine ýerleşer.

<nav class="nav nav-pills flex-column flex-sm-row">
  <a class="flex-sm-fill text-sm-center nav-link active" aria-current="page" href="#">Active</a>
  <a class="flex-sm-fill text-sm-center nav-link" href="#">Longer nav link</a>
  <a class="flex-sm-fill text-sm-center nav-link" href="#">Link</a>
  <a class="flex-sm-fill text-sm-center nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</nav>

Elýeterlilik barada

Nawigasiýa zolagyny üpjün etmek üçin deňiz güýçlerini ulanýan bolsaňyz role="navigation", iň logiki ene konteýnerine goşuň <ul>ýa-da <nav>tutuş nawigasiýa elementini gurşap alyň. Roly özüne goşmaň <ul>, sebäbi bu kömekçi tehnologiýalar arkaly hakyky sanaw hökmünde yglan edilmeginiň öňüni alar.

Nawigasiýa panelleriniň, .nav-tabssynp bilen tablisa görnüşinde wizual görnüşde düzülen hem bolsa, berilmeli däldigini ýarole="tablist" - role="tab"da role="tabpanel"atributlarynyň bolmaly däldigini unutmaň. Bular diňe WAI ARIA awtorlaşdyryş amallarynda beýan edilişi ýaly dinamiki tablisaly interfeýsler üçin laýyk gelýär . Mysal üçin bu bölümdäki dinamiki goýlan interfeýsler üçin JavaScript häsiýetine serediň . Aýratynlyk dinamiki goýlan interfeýslerde hökmany däl, sebäbi JavaScript işjeň goýmany aria-currentgoşmak bilen saýlanan ýagdaýy dolandyrýar .aria-selected="true"

Açylýan ýerleri ulanmak

Birneme goşmaça HTML we açylan JavaScript plugin bilen açylýan menýulary goşuň .

Açylýan bellikler

<ul class="nav nav-tabs">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
    <ul class="dropdown-menu">
      <li><a class="dropdown-item" href="#">Action</a></li>
      <li><a class="dropdown-item" href="#">Another action</a></li>
      <li><a class="dropdown-item" href="#">Something else here</a></li>
      <li><hr class="dropdown-divider"></li>
      <li><a class="dropdown-item" href="#">Separated link</a></li>
    </ul>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

Açylýan dermanlar

<ul class="nav nav-pills">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
    <ul class="dropdown-menu">
      <li><a class="dropdown-item" href="#">Action</a></li>
      <li><a class="dropdown-item" href="#">Another action</a></li>
      <li><a class="dropdown-item" href="#">Something else here</a></li>
      <li><hr class="dropdown-divider"></li>
      <li><a class="dropdown-item" href="#">Separated link</a></li>
    </ul>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
  </li>
</ul>

Sass

Üýtgeýjiler

$nav-link-padding-y:                .5rem;
$nav-link-padding-x:                1rem;
$nav-link-font-size:                null;
$nav-link-font-weight:              null;
$nav-link-color:                    $link-color;
$nav-link-hover-color:              $link-hover-color;
$nav-link-transition:               color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out;
$nav-link-disabled-color:           $gray-600;

$nav-tabs-border-color:             $gray-300;
$nav-tabs-border-width:             $border-width;
$nav-tabs-border-radius:            $border-radius;
$nav-tabs-link-hover-border-color:  $gray-200 $gray-200 $nav-tabs-border-color;
$nav-tabs-link-active-color:        $gray-700;
$nav-tabs-link-active-bg:           $body-bg;
$nav-tabs-link-active-border-color: $gray-300 $gray-300 $nav-tabs-link-active-bg;

$nav-pills-border-radius:           $border-radius;
$nav-pills-link-active-color:       $component-active-color;
$nav-pills-link-active-bg:          $component-active-bg;

JavaScript häsiýeti

bootstrap.jsJavaerli mazmunyň tablisa panellerini döretmek üçin nawigasiýa belliklerimizi we tabletkalarymyzy giňeltmek üçin JavaScript pluginini ulanyň - ony aýratyn ýa-da düzülen faýl arkaly goşuň.

WAI ARIA Awtorlaşdyryş amallarynda beýan edilişi ýaly dinamiki bellikli interfeýsler, kömekçi tehnologiýalary ulanyjylara (ekran okyjylary ýaly) gurluşyny , işleýşini we häzirki ýagdaýyny ýetirmek üçin zerur we goşmaça atributlary talap edýär role="tablist". Iň oňat tejribe hökmünde, bellikler üçin elementleri ulanmagy maslahat berýäris , sebäbi bular täze sahypa ýa-da ýerleşişe däl-de, dinamiki üýtgeşmä itergi berýän dolandyryşlardyr.role="tab"role="tabpanel"aria-<button>

Dinamiki bellikli interfeýslerde aşak düşýän menýular bolmaly däldir , sebäbi bu ulanylyş we elýeterlilik meselesini döredýär. Ulanyş nukdaýnazaryndan, häzirki görkezilen goýmanyň trigger elementiniň derrew görünmeýänligi (ýapyk açylan menýunyň içinde bolşy ýaly) bulaşyklyga sebäp bolup biler. Elýeterlilik nukdaýnazaryndan häzirki wagtda bu görnüşli gurluşy adaty WAI ARIA nagyşyna kartalaşdyrmagyň manyly usuly ýok, bu kömekçi tehnologiýalary ulanyjylara aňsatlyk bilen düşünip bolmaýar.

Bu, Öý goýmasynyň baglanyşykly mazmuny. Başga bir goýmany bassaňyz, indiki üçin görnükliligini üýtgeder. JavaScript goýmasy, mazmunyň görünmegine we stiline gözegçilik etmek üçin sapaklary çalyşýar. Salgylar, dermanlar we beýleki .navgüýçli nawigasiýa bilen ulanyp bilersiňiz.

This is some placeholder content the Profile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Contact tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Contact</button>
  </li>
</ul>
<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
  <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
</div>

Islegleriňize laýyk gelmek üçin, bu <ul>ýokarda görkezilişi ýaly esasly bellik bilen ýa-da islendik özbaşdak “özüňizi aýlaň” belligi bilen işleýär. Ulanylýan bolsaňyz <nav>, oňa gönüden-göni goşmaly däldigiňize üns beriň role="tablist", sebäbi bu elementiň nawigasiýa belligi hökmünde ýerli roluny ýok eder. Munuň ýerine alternatiw elemente geçiň (aşakdaky mysalda ýönekeý <div>) we <nav>daşyny gurşap alyň.

<nav>
  <div class="nav nav-tabs" id="nav-tab" role="tablist">
    <button class="nav-link active" id="nav-home-tab" data-bs-toggle="tab" data-bs-target="#nav-home" type="button" role="tab" aria-controls="nav-home" aria-selected="true">Home</button>
    <button class="nav-link" id="nav-profile-tab" data-bs-toggle="tab" data-bs-target="#nav-profile" type="button" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</button>
    <button class="nav-link" id="nav-contact-tab" data-bs-toggle="tab" data-bs-target="#nav-contact" type="button" role="tab" aria-controls="nav-contact" aria-selected="false">Contact</button>
  </div>
</nav>
<div class="tab-content" id="nav-tabContent">
  <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">...</div>
  <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">...</div>
  <div class="tab-pane fade" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab">...</div>
</div>

Salgylar plugin hem dermanlar bilen işleýär.

Bu, Öý goýmasynyň baglanyşykly mazmuny. Başga bir goýmany bassaňyz, indiki üçin görnükliligini üýtgeder. JavaScript goýmasy, mazmunyň görünmegine we stiline gözegçilik etmek üçin sapaklary çalyşýar. Salgylar, dermanlar we beýleki .navgüýçli nawigasiýa bilen ulanyp bilersiňiz.

This is some placeholder content the Profile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Contact tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="pills-home-tab" data-bs-toggle="pill" data-bs-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="pills-profile-tab" data-bs-toggle="pill" data-bs-target="#pills-profile" type="button" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
  </li>
</ul>
<div class="tab-content" id="pills-tabContent">
  <div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">...</div>
  <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">...</div>
  <div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">...</div>
</div>

Wertikal dermanlar bilen.

Bu, Öý goýmasynyň baglanyşykly mazmuny. Başga bir goýmany bassaňyz, indiki üçin görnükliligini üýtgeder. JavaScript goýmasy, mazmunyň görünmegine we stiline gözegçilik etmek üçin sapaklary çalyşýar. Salgylar, dermanlar we beýleki .navgüýçli nawigasiýa bilen ulanyp bilersiňiz.

This is some placeholder content the Profile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Messages tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Settings tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

<div class="d-flex align-items-start">
  <div class="nav flex-column nav-pills me-3" id="v-pills-tab" role="tablist" aria-orientation="vertical">
    <button class="nav-link active" id="v-pills-home-tab" data-bs-toggle="pill" data-bs-target="#v-pills-home" type="button" role="tab" aria-controls="v-pills-home" aria-selected="true">Home</button>
    <button class="nav-link" id="v-pills-profile-tab" data-bs-toggle="pill" data-bs-target="#v-pills-profile" type="button" role="tab" aria-controls="v-pills-profile" aria-selected="false">Profile</button>
    <button class="nav-link" id="v-pills-messages-tab" data-bs-toggle="pill" data-bs-target="#v-pills-messages" type="button" role="tab" aria-controls="v-pills-messages" aria-selected="false">Messages</button>
    <button class="nav-link" id="v-pills-settings-tab" data-bs-toggle="pill" data-bs-target="#v-pills-settings" type="button" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</button>
  </div>
  <div class="tab-content" id="v-pills-tabContent">
    <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">...</div>
    <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">...</div>
    <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">...</div>
    <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">...</div>
  </div>
</div>

Maglumat atributlaryny ulanmak

data-bs-toggle="tab"Diňe bir elementi ýa-da bir elementi görkezip, hiç hili JavaScript ýazmazdan bir tab ýa-da tablet nawigasiýasyny işjeňleşdirip bilersiňiz data-bs-toggle="pill". Bu maglumat atributlaryny ulanyň ýa- .nav-tabsda .nav-pills.

<!-- Nav tabs -->
<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="messages-tab" data-bs-toggle="tab" data-bs-target="#messages" type="button" role="tab" aria-controls="messages" aria-selected="false">Messages</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="settings-tab" data-bs-toggle="tab" data-bs-target="#settings" type="button" role="tab" aria-controls="settings" aria-selected="false">Settings</button>
  </li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
  <div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
  <div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
  <div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
</div>

JavaScript arkaly

JavaScript arkaly tablisa tablisalaryny açyň (her tab aýratynlykda işjeňleşdirilmeli):

var triggerTabList = [].slice.call(document.querySelectorAll('#myTab a'))
triggerTabList.forEach(function (triggerEl) {
  var tabTrigger = new bootstrap.Tab(triggerEl)

  triggerEl.addEventListener('click', function (event) {
    event.preventDefault()
    tabTrigger.show()
  })
})

Aýry-aýry bellikleri birnäçe usul bilen işjeňleşdirip bilersiňiz:

var triggerEl = document.querySelector('#myTab a[href="#profile"]')
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name

var triggerFirstTabEl = document.querySelector('#myTab li:first-child a')
bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab

Öçürilen effekt

Salgylaryň ýitmegi .fadeüçin hersine goşuň .tab-pane. Ilkinji goýma paneli .showbaşlangyç mazmuny görünmeli.

<div class="tab-content">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
  <div class="tab-pane fade" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
  <div class="tab-pane fade" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
</div>

Usullar

Asynkron usullar we geçişler

APIhli API usullary asynkron bolup, geçişe başlaýar . Geçiş başlan badyna, ýöne gutarmanka jaň edijä gaýdyp gelýärler . Mundan başga-da, geçiş komponentine çagyryş usuly hasaba alynmaz .

Has giňişleýin maglumat üçin JavaScript resminamalarymyza serediň .

constructor

Salgy elementini we mazmun gapyny işjeňleşdirýär. Salgyda DOM-daky konteýner düwünini nyşana alýan bir data-bs-targetbaglanyşyk ýa-da bir atribut bolmaly.href

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="messages-tab" data-bs-toggle="tab" data-bs-target="#messages" type="button" role="tab" aria-controls="messages" aria-selected="false">Messages</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="settings-tab" data-bs-toggle="tab" data-bs-target="#settings" type="button" role="tab" aria-controls="settings" aria-selected="false">Settings</button>
  </li>
</ul>

<div class="tab-content">
  <div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
  <div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
  <div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
  <div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
</div>

<script>
  var firstTabEl = document.querySelector('#myTab li:last-child a')
  var firstTab = new bootstrap.Tab(firstTabEl)

  firstTab.show()
</script>

görkezmek

Berlen goýmany saýlaýar we baglanyşykly paneli görkezýär. Öň saýlanan başga bir tab saýlanmaýar we oňa bagly panel gizlenýär. Salgy paneli hakykatdanam görkezilmänkä (ýagny shown.bs.tabwaka ýüze çykmazdan ozal) jaň edijä gaýdyp gelýär.

  var someTabTriggerEl = document.querySelector('#someTabTrigger')
  var tab = new bootstrap.Tab(someTabTriggerEl)

  tab.show()

taşlaň

Bir elementiň goýmasyny ýok edýär.

GetInstance

DOM elementi bilen baglanyşykly tab mysalyny almaga mümkinçilik berýän statiki usul

var triggerEl = document.querySelector('#trigger')
var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance

getOrCreateInstance

DOM elementi bilen baglanyşykly tablisa mysalyny almaga ýa-da başlamadyk ýagdaýynda täzesini döretmäge mümkinçilik berýän statiki usul.

var triggerEl = document.querySelector('#trigger')
var tab = bootstrap.Tab.getOrCreateInstance(triggerEl) // Returns a Bootstrap tab instance

Wakalar

Täze tab görkezilende wakalar aşakdaky tertipde ýanýar:

  1. hide.bs.tab(häzirki işjeň goýmada)
  2. show.bs.tab(görkezilmeli goýmada)
  3. hidden.bs.tabhide.bs.tab(öňki işjeň goýmada, waka bilen birmeňzeş )
  4. shown.bs.tabshow.bs.tab(täze işjeň görkezilen ýaňy görkezilen goýmada, waka bilen birmeňzeş )

Hiç bir goýma eýýäm işjeň bolmadyk bolsa, wakalar hide.bs.tabwe hidden.bs.tabwakalar atylmaz.

Çäräniň görnüşi Düşündiriş
show.bs.tab Bu waka tab goýmasynda ýanýar, ýöne täze goýma görkezilmänkä. Işjeň goýmany we öňki işjeň goýmany degişlilikde ulanyň event.targetwe nyşana alyň.event.relatedTarget
shown.bs.tab Bu waka, görkezme görkezilenden soň tab goýmasynda ýanýar. Işjeň goýmany we öňki işjeň goýmany degişlilikde ulanyň event.targetwe nyşana alyň.event.relatedTarget
hide.bs.tab Bu waka täze goýma görkezilmeli bolanda ýanýar (we şeýlelik bilen öňki işjeň goýma gizlenmeli). Häzirki işjeň goýmany we ýakyn wagtda işjeň boljak täze goýmany ulanyň event.targetwe nyşana alyň.event.relatedTarget
hidden.bs.tab Bu waka täze goýma görkezilenden soň ýanýar (we şeýlelik bilen öňki işjeň goýma gizlenýär). Öňki işjeň goýmany we täze işjeň goýmany degişlilikde ulanyň event.targetwe nyşana alyň.event.relatedTarget
var tabEl = document.querySelector('button[data-bs-toggle="tab"]')
tabEl.addEventListener('shown.bs.tab', function (event) {
  event.target // newly activated tab
  event.relatedTarget // previous active tab
})