Navs
Nyaraka na mifano ya jinsi ya kutumia vipengee vya urambazaji vilivyojumuishwa vya Bootstrap.
Nav ya msingi
Urambazaji unapatikana katika muundo na mitindo ya jumla ya kushiriki Bootstrap, kutoka .nav
darasa la msingi hadi majimbo amilifu na ya walemavu. Badilisha madarasa ya kurekebisha ili kubadili kati ya kila mtindo.
Sehemu ya msingi .nav
imejengwa kwa flexbox na kutoa msingi imara wa kujenga aina zote za vipengele vya urambazaji. Inajumuisha ubatilishaji wa mitindo fulani (ya kufanya kazi na orodha), baadhi ya miunganisho ya viungo kwa maeneo makubwa zaidi, na mitindo ya kimsingi iliyozimwa.
.nav
haijumuishi
.active
jimbo lolote. Mifano ifuatayo ni pamoja na darasa, haswa ili kuonyesha kuwa darasa hili halichochei mtindo wowote maalum.
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" 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">Disabled</a>
</li>
</ul>
Madarasa hutumiwa kote, kwa hivyo lebo yako inaweza kunyumbulika sana. Tumia <ul>
s kama ilivyo hapo juu, <ol>
ikiwa mpangilio wa vitu vyako ni muhimu, au pindua yako na <nav>
kipengee. Kwa sababu .nav
matumizi display: flex
, viungo vya nav hufanya kazi sawa na vipengee vya nav, lakini bila ghafi ya ziada.
<nav class="nav">
<a class="nav-link active" href="#">Active</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link disabled">Disabled</a>
</nav>
Mitindo inayopatikana
Badilisha mtindo wa .nav
sehemu ya s na virekebishaji na huduma. Changanya na ulinganishe inavyohitajika, au ujenge yako mwenyewe.
Mpangilio wa mlalo
Badilisha mpangilio mlalo wa nav yako na huduma za flexbox . Kwa chaguo-msingi, navs zimepangiliwa kushoto, lakini unaweza kuzibadilisha kwa urahisi hadi zikiwa zimepangiliwa katikati au kulia.
Iliyowekwa katikati na .justify-content-center
:
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" 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">Disabled</a>
</li>
</ul>
Inayolingana na .justify-content-end
:
<ul class="nav justify-content-end">
<li class="nav-item">
<a class="nav-link active" 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">Disabled</a>
</li>
</ul>
Wima
Ratibu urambazaji wako kwa kubadilisha mwelekeo wa kipengee rahisi na .flex-column
matumizi. Je! unahitaji kuziweka kwenye tovuti zingine za kutazama lakini sio zingine? Tumia matoleo sikivu (kwa mfano, .flex-sm-column
).
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" 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">Disabled</a>
</li>
</ul>
Kama kawaida, urambazaji wima unawezekana bila <ul>
s, pia.
<nav class="nav flex-column">
<a class="nav-link active" href="#">Active</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link disabled">Disabled</a>
</nav>
Vichupo
Huchukua nav ya msingi kutoka juu na kuongeza .nav-tabs
darasa ili kutoa kiolesura chenye kichupo. Zitumie kuunda maeneo yanayoweza kutekelezeka na kichupo chetu cha programu jalizi ya JavaScript .
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" 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">Disabled</a>
</li>
</ul>
Vidonge
Chukua HTML hiyo hiyo, lakini tumia .nav-pills
badala yake:
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" 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">Disabled</a>
</li>
</ul>
Jaza na uhalalishe
Lazimisha .nav
yaliyomo yako kupanua upana kamili unaopatikana moja ya aina mbili za kirekebishaji. Ili kujaza nafasi zote zinazopatikana kwa uwiano .nav-item
, tumia .nav-fill
. Tambua kuwa nafasi yote ya mlalo imekaliwa, lakini si kila kipengee cha nav kina upana sawa.
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a class="nav-link active" 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">Disabled</a>
</li>
</ul>
Unapotumia <nav>
urambazaji unaotegemea, unaweza kuacha kwa usalama .nav-item
kama .nav-link
inavyohitajika tu kwa <a>
vipengele vya kupiga maridadi.
<nav class="nav nav-pills nav-fill">
<a class="nav-link active" 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">Disabled</a>
</nav>
Kwa vipengele vya upana sawa, tumia .nav-justified
. Nafasi yote ya mlalo itakaliwa na viungo vya nav, lakini tofauti na ilivyo .nav-fill
hapo juu, kila kipengee cha nav kitakuwa na upana sawa.
<ul class="nav nav-pills nav-justified">
<li class="nav-item">
<a class="nav-link active" 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">Disabled</a>
</li>
</ul>
Sawa na .nav-fill
mfano kutumia <nav>
urambazaji-msingi.
<nav class="nav nav-pills nav-justified">
<a class="nav-link active" 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">Disabled</a>
</nav>
Kufanya kazi na huduma za kubadilika
Ikiwa unahitaji tofauti za nav zinazojibu, zingatia kutumia mfululizo wa huduma za flexbox . Ingawa ni ya kitenzi zaidi, huduma hizi hutoa ubinafsishaji zaidi katika sehemu zote za kujibu. Katika mfano ulio hapa chini, nav yetu itapangwa kwenye sehemu ya chini kabisa ya kukatika, kisha itengeneze kwa mpangilio mlalo unaojaza upana unaopatikana kuanzia sehemu ndogo ya kukatika.
<nav class="nav nav-pills flex-column flex-sm-row">
<a class="flex-sm-fill text-sm-center nav-link active" 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">Disabled</a>
</nav>
Kuhusu ufikivu
Ikiwa unatumia navs kutoa upau wa kusogeza, hakikisha kuwa umeongeza kwenye role="navigation"
kontena kuu la kimantiki zaidi la <ul>
, au funika <nav>
kipengee kwenye usogezaji wote. Usiongeze jukumu kwenye <ul>
yenyewe, kwani hii inaweza kuizuia kutangazwa kama orodha halisi na teknolojia saidizi.
Kumbuka kuwa pau za kusogeza, hata zikiwekwa mtindo wa kuonekana kama vichupo na .nav-tabs
darasa, hazipaswi kupewa , role="tablist"
au role="tab"
sifa role="tabpanel"
. Hizi zinafaa tu kwa violesura vinavyobadilika vya vichupo, kama ilivyofafanuliwa katika muundo wa vichupo vya Mwongozo wa Mazoea ya Uandishi wa ARIA . Tazama tabia ya JavaScript kwa violesura vinavyobadilika vya vichupo katika sehemu hii kwa mfano.
Kwa kutumia menyu kunjuzi
Ongeza menyu kunjuzi na HTML ya ziada kidogo na programu- jalizi ya JavaScript .
Vichupo vilivyo na menyu kunjuzi
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
Vidonge vilivyo na kushuka
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
Tabia ya JavaScript
Tumia kichupo cha programu-jalizi ya JavaScript—ijumuishe kibinafsi au kupitia faili iliyokusanywa bootstrap.js
—ili kupanua vichupo vyetu vya kusogeza na vidonge ili kuunda vidirisha vinavyoweza kutekelezeka vya maudhui ya ndani.
Ikiwa unaunda JavaScript yetu kutoka kwa chanzo, inahitajiutil.js
.
Violesura vyenye vichupo vinavyobadilika, kama ilivyofafanuliwa katika muundo wa vichupo vya Mwongozo wa Mazoezi ya Uandishi wa ARIA , huhitaji role="tablist"
, role="tab"
, role="tabpanel"
, na sifa za ziada aria-
ili kuwasilisha muundo wao, utendakazi na hali ya sasa kwa watumiaji wa teknolojia saidizi (kama vile visoma skrini). Kama mbinu bora, tunapendekeza kutumia <button>
vipengele vya vichupo, kwa kuwa hivi ni vidhibiti vinavyoanzisha mabadiliko yanayobadilika, badala ya viungo vinavyoelekeza kwenye ukurasa mpya au eneo.
Maudhui ya kishika nafasi kwa kidirisha cha kichupo. Hii inahusiana na kichupo cha nyumbani. Hukupeleka juu maili, juu sana, kwa sababu ana tabasamu hilo moja la kimataifa. Kuna mgeni kitandani mwangu, kuna pigo katika kichwa changu. La, hapana. Katika maisha mengine ningekufanya ubaki. Maana mimi, nina uwezo wa chochote. Kufaa kwa vita yangu ya taji. Inatumika kuiba pombe ya wazazi wako na kupanda juu ya paa. Toni, tan inafaa na tayari, igeuze kusababisha kupata kwake kuwa nzito. Upendo wake ni kama dawa. Nadhani nilisahau nilikuwa na chaguo.
Maudhui ya kishika nafasi kwa kidirisha cha kichupo. Hii inahusiana na kichupo cha wasifu. Umepata usanifu bora zaidi. Mihuri ya pasipoti, yeye ni wa ulimwengu wote. Safi, safi, kali, tumeiweka kwenye kufuli. Sikuwahi kupanga kuwa siku moja nitakuwa nimekupoteza. Anakula moyo wako. Busu yako ni ya ulimwengu, kila hatua ni uchawi. Ninamaanisha wale, ninamaanisha kama yeye ndiye. Salamu wapendwa tufunge safari. Imiliki tu usiku kama tarehe 4 Julai! Lakini afadhali upoteze.
Placeholder content for the tab panel. This one relates to the contact tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="home-tab" data-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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>
Ili kukusaidia kutosheleza mahitaji yako, hii inafanya kazi na <ul>
alama-msingi, kama inavyoonyeshwa hapo juu, au kwa lebo yoyote ya kiholela ya "weka yako mwenyewe". Kumbuka kuwa ikiwa unatumia <nav>
, hupaswi kuiongeza role="tablist"
moja kwa moja, kwani hii ingebatilisha jukumu asili la kipengele kama alama muhimu ya urambazaji. Badala yake, badilisha kwa kipengee mbadala (katika mfano hapa chini, rahisi <div>
) na uifunge <nav>
kuzunguka.
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
<button class="nav-link active" id="nav-home-tab" data-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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>
Programu-jalizi ya tabo pia inafanya kazi na vidonge.
Maudhui ya kishika nafasi kwa kidirisha cha kichupo. Hii inahusiana na kichupo cha nyumbani. Hukupeleka juu maili, juu sana, kwa sababu ana tabasamu hilo moja la kimataifa. Kuna mgeni kitandani mwangu, kuna pigo katika kichwa changu. La, hapana. Katika maisha mengine ningekufanya ubaki. Maana mimi, nina uwezo wa chochote. Kufaa kwa vita yangu ya taji. Inatumika kuiba pombe ya wazazi wako na kupanda juu ya paa. Toni, tan inafaa na tayari, igeuze kusababisha kupata kwake kuwa nzito. Upendo wake ni kama dawa. Nadhani nilisahau nilikuwa na chaguo.
Placeholder content for the tab panel. This one relates to the profile tab. You got the finest architecture. Passport stamps, she's cosmopolitan. Fine, fresh, fierce, we got it on lock. Never planned that one day I'd be losing you. She eats your heart out. Your kiss is cosmic, every move is magic. I mean the ones, I mean like she's the one. Greetings loved ones let's take a journey. Just own the night like the 4th of July! But you'd rather get wasted.
Placeholder content for the tab panel. This one relates to the contact tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.
<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-toggle="pill" data-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-toggle="pill" data-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-toggle="pill" data-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>
Na kwa vidonge vya wima.
Maudhui ya kishika nafasi kwa kidirisha cha kichupo. Hii inahusiana na kichupo cha nyumbani. Nilikuona katikati ya jiji ukiimba Blues. Tazama ukizunguka mkondo wa maji. Kwa nini usiniruhusu nipite? Nzito ni kichwa kinachovaa taji. Naam, tunafanya malaika walie, mvua ikinyesha juu ya nchi kutoka juu. Unataka kuona kipindi katika 3D, filamu. Je! umewahi kuhisi, kuhisi karatasi nyembamba sana. Ni ndiyo au hapana, hapana labda.
Placeholder content for the tab panel. This one relates to the profile tab. Takes you miles high, so high, 'cause she’s got that one international smile. There's a stranger in my bed, there's a pounding in my head. Oh, no. In another life I would make you stay. ‘Cause I, I’m capable of anything. Suiting up for my crowning battle. Used to steal your parents' liquor and climb to the roof. Tone, tan fit and ready, turn it up cause its gettin' heavy. Her love is like a drug. I guess that I forgot I had a choice.
Placeholder content for the tab panel. This one relates to the messages tab. You got the finest architecture. Passport stamps, she's cosmopolitan. Fine, fresh, fierce, we got it on lock. Never planned that one day I'd be losing you. She eats your heart out. Your kiss is cosmic, every move is magic. I mean the ones, I mean like she's the one. Greetings loved ones let's take a journey. Just own the night like the 4th of July! But you'd rather get wasted.
Placeholder content for the tab panel. This one relates to the settings tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.
<div class="row">
<div class="col-3">
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<button class="nav-link active" id="v-pills-home-tab" data-toggle="pill" data-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-toggle="pill" data-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-toggle="pill" data-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-toggle="pill" data-target="#v-pills-settings" type="button" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</button>
</div>
</div>
<div class="col-9">
<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>
</div>
Kutumia sifa za data
Unaweza kuwezesha urambazaji wa kichupo au kidonge bila kuandika JavaScript yoyote kwa kubainisha data-toggle="tab"
au data-toggle="pill"
kwa kipengee. Tumia sifa hizi za data kwenye .nav-tabs
au .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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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>
Kupitia JavaScript
Washa vichupo vinavyoweza kutekelezeka kupitia JavaScript (kila kichupo kinahitaji kuamilishwa kivyake):
$('#myTab button').on('click', function (event) {
event.preventDefault()
$(this).tab('show')
})
Unaweza kuwezesha tabo binafsi kwa njia kadhaa:
$('#myTab button[data-target="#profile"]').tab('show') // Select tab by name
$('#myTab li:first-child button').tab('show') // Select first tab
$('#myTab li:last-child button').tab('show') // Select last tab
$('#myTab li:nth-child(3) button').tab('show') // Select third tab
Fifisha athari
Ili kufanya vichupo kufifia, ongeza .fade
kwa kila .tab-pane
. Kidirisha cha kichupo cha kwanza lazima pia kiwe na .show
maudhui ya awali kuonekana.
<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>
Mbinu
Njia za Asynchronous na mabadiliko
Njia zote za API ni za asynchronous na zinaanzisha mpito . Wanarudi kwa mpigaji mara tu mpito unapoanza lakini kabla haujaisha . Kwa kuongeza, simu ya mbinu kwenye sehemu ya mpito itapuuzwa .
$().kichupo
Huwasha kipengele cha kichupo na kontena ya maudhui. Kichupo kinapaswa kuwa na ama data-target
, ikiwa kinatumia kiungo, href
sifa inayolenga nodi ya kontena katika DOM.
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="home-tab" data-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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>
$(function () {
$('#myTab li:last-child button').tab('show')
})
</script>
.tab('onyesha')
Huchagua kichupo kilichotolewa na kuonyesha kidirisha chake kinachohusiana. Kichupo kingine chochote ambacho kilichaguliwa hapo awali kitaacha kuchaguliwa na kidirisha chake kinachohusishwa hufichwa. Hurejesha kwa mpigaji kabla kidirisha cha kichupo hakijaonyeshwa (yaani kabla ya shown.bs.tab
tukio kutokea).
$('#someTab').tab('show')
.tab('ondoa')
Huharibu kichupo cha kipengele.
Matukio
Wakati wa kuonyesha kichupo kipya, matukio huwaka kwa mpangilio ufuatao:
hide.bs.tab
(kwenye kichupo kinachotumika sasa)show.bs.tab
(kwenye kichupo cha-kuonyeshwa)hidden.bs.tab
(kwenye kichupo amilifu kilichotangulia, sawa na chahide.bs.tab
tukio)shown.bs.tab
(kwenye kichupo kipya-kilichoonyeshwa, sawa na chashow.bs.tab
tukio)
Ikiwa hakuna kichupo kilichokuwa tayari kinatumika, basi matukio hide.bs.tab
na hidden.bs.tab
matukio hayatafutwa.
Aina ya Tukio | Maelezo |
---|---|
kichupo cha.bs | Tukio hili linawaka kwenye onyesho la kichupo, lakini kabla ya kichupo kipya kuonyeshwa. Tumia event.target na event.relatedTarget kulenga kichupo amilifu na kichupo amilifu cha awali (kama kinapatikana) mtawalia. |
kichupo.cha.bs | Tukio hili huwashwa kwenye onyesho la kichupo baada ya kichupo kuonyeshwa. Tumia event.target na event.relatedTarget kulenga kichupo amilifu na kichupo amilifu cha awali (kama kinapatikana) mtawalia. |
Ficha.bs.kichupo | Tukio hili huwaka wakati kichupo kipya kitaonyeshwa (na kwa hivyo kichupo amilifu cha awali kitafichwa). Tumia event.target na event.relatedTarget kulenga kichupo kinachotumika sasa na kichupo kipya kitakachotumika hivi karibuni, mtawalia. |
kichupo.bs.fiche | Tukio hili huwaka baada ya kichupo kipya kuonyeshwa (na kwa hivyo kichupo amilifu cha awali kimefichwa). Tumia event.target na event.relatedTarget kulenga kichupo amilifu cha awali na kichupo kipya kinachotumika, mtawalia. |
$('button[data-toggle="tab"]').on('shown.bs.tab', function (event) {
event.target // newly activated tab
event.relatedTarget // previous active tab
})