JavaScript

Zisa izinto ze-Bootstrap ebomini-ngoku kunye neeplagi ze-jQuery zesiko ezili-13.

Umntu ngamnye okanye uqokelelwe

Iiplagi zingabandakanywa ngokwahlukeneyo (nangona ezinye zifuna ukuxhomekeka), okanye zonke ngaxeshanye. Zombini i- bootstrap.js kunye ne- bootstrap.min.js ziqulathe zonke iiplagi ezifakiweyo kwifayile enye.

Iimpawu zedatha

Ungasebenzisa zonke iiplagi ze-Bootstrap ngaphandle kwe-API yokuphawula ngaphandle kokubhala umgca omnye weJavaScript. Le yi-API yeklasi yokuqala ye-Bootstrap kwaye kufuneka ibe yingqwalasela yakho yokuqala xa usebenzisa iplagi.

Oko kwathiwa, kwezinye iimeko kunokunqweneleka ukucima lo msebenzi. Ngoko ke, sikwabonelela ngokukwazi ukuvala uphawu loyelelwano lwedatha i-API ngokukhulula zonke iziganeko kumzimba wegama elifakwe `'idatha-api'`. Oku kukhangeleka ngolu hlobo:

  1. $ ( 'umzimba' ). cima ( '.data-api' )

Kungenjalo, ukujolisa iplagin ethile, faka nje igama leplagi njengendawo yegama kunye ne-data-api namespace efana nale:

  1. $ ( 'umzimba' ). cima ( '.alert.data-api' )

Programmatic API

Sikwakholelwa ukuba kufuneka ukwazi ukusebenzisa zonke iiplagi zeBootstrap ngeJavaScript API. Zonke ii-API zikawonke-wonke zinye, iindlela ezibolekwayo, kwaye zibuyisela ingqokelela eyenziwayo.

  1. $ ( ".btn.danger" ). iqhosha ( "toggle" ). addClass ( "amafutha" )

Zonke iindlela kufuneka zamkele into ekhethiweyo yeenketho, umtya ojolise kwindlela ethile, okanye akukho nto (eqalisa iplagin ngokuziphatha okungagqibekanga):

  1. $ ( "#myModal" ). imodal () // iqaliswe ngokumiselweyo
  2. $ ( "#myModal" ). imodal ({ ikhibhodi : bubuxoki }) // iqaliswe ngaphandle kwebhodi yezitshixo
  3. $ ( "#myModal" ). imodal ( 'show' ) // iqalisa kwaye izibhengezo zibonise ngoko nangoko

I-plugin nganye ikwaveza umakhi wayo ekrwada kwipropati `yoMakhi`: $.fn.popover.Constructor. Ukuba ungathanda ukufumana umzekelo othile we-plugin, yifumane ngokuthe ngqo kwinto: $('[rel=popover]').data('popover').

Iziganeko

I-Bootstrap ibonelela ngeziganeko zesiko kwizinto ezininzi ezizodwa ze-plugin. Ngokubanzi, ezi ziza ngendlela engapheliyo kunye neyexesha elidlulileyo - apho i-infinitive (umz. show) iqaliswa ekuqaleni kwesiganeko, kunye nemo yaso yexesha elidlulileyo ye-participle form (umz. shown) iqala ekugqityweni kwesenzo.

Zonke iziganeko ezingapheliyo zibonelela ngokusebenza kokuthintelaMiselweyo. Oku kunika amandla okumisa ukuphunyezwa kwesenzo phambi kokuba siqale.

  1. $ ( '#myModal' ). kwi ( 'bonisa' , umsebenzi ( e ) {
  2. ukuba (! data ) buyisela e . preventDefault () // iyamisa imodal ekubonisweni
  3. })

Malunga neenguqu

Ngeziphumo ezilula zotshintsho, quka i-bootstrap-transition.js kanye ecaleni kwezinye iifayile ze-JS. Ukuba usebenzisa i compiled (okanye minified) bootstrap.js, akukho mfuneko yokuquka oku—sele kukho.

Sebenzisa iimeko

Imizekelo embalwa ye-plugin yotshintsho:

  • Ukutyibilika okanye ukuncipha kwiimodyuli
  • Ukucima iithebhu
  • Ukucima izilumkiso
  • Iipaneli zecarousel ezityibilikayo

Imizekelo

Iimodyuli zilungelelanisiwe, kodwa zibhetyebhetye, iingxoxo zencoko yababini ezinobuncinci obufunekayo obufunekayo kunye nokungagqibekanga okuhlakaniphile.

Umzekelo omileyo

Imodali enikezelweyo enesihloko, umzimba, kunye neseti yezenzo kumbhalo osemazantsi.

  1. <div iklasi = "i-modal hide fade" >
  2. <div class = "modal-header" >
  3. < uhlobo lweqhosha = "iqhosha" class = "close" data-dismiss = "modal" aria-hidden = "true" > × </ iqhosha>
  4. <h3> imodal header </h3>
  5. </ div>
  6. <div class = "modal-body" >
  7. <p> Umzimba omnye olungileyo… </p>
  8. </ div>
  9. <div class = "modal-footer" >
  10. <a href = "#" iklasi = "btn"> Vala </a> _
  11. <a href = "#" class = "btn btn-primary"> Gcina utshintsho </a>
  12. </ div>
  13. </ div>

Idemo ephilayo

Guqula imodal usebenzisa iJavaScript ngokucofa iqhosha elingezantsi. Iza kutyibilika phantsi kwaye iphele ukusuka phezulu ephepheni.

  1. <!-- Iqhosha lokucupha imodal -->
  2. <a href = "#myModal" role = "iqhosha" iklasi = "btn" data-toggle = "modal" > Qalisa indlela yedemo </a>
  3.  
  4. <!-- Modal -->
  5. <div id = "myModal" class = "modal hide fade" tabindex = "-1" indima = "dialog" aria-labelledby = "myModalLabel" aria- hidden = "true" >
  6. <div class = "modal-header" >
  7. < uhlobo lweqhosha = "iqhosha" class = "close" data-dismiss = "modal" aria-hidden = "true" > × </ iqhosha>
  8. <h3 id = "myModalLabel" > Intloko yeModal </h3>
  9. </ div>
  10. <div class = "modal-body" >
  11. <p> Umzimba omnye olungileyo… </p>
  12. </ div>
  13. <div class = "modal-footer" >
  14. < iklasi yeqhosha = "btn" data-dismiss = "modal" aria-hidden = "true" > Vala </ iqhosha>
  15. < iklasi yeqhosha = "btn btn-primary" > Gcina utshintsho </ iqhosha>
  16. </ div>
  17. </ div>

Ukusetyenziswa

Ngeempawu zedatha

Vula imodali ngaphandle kokubhala iJavaScript. Cwangcisa data-toggle="modal"isiqalelo somlawuli, njengeqhosha, kunye ne data-target="#foo"okanye href="#foo"ukujolisa kwindlela ethile yokuguqula.

  1. < uhlobo lweqhosha = "iqhosha" data-toggle = "modal" data-target = "#myModal" > Yandulula indlela </iqhosha>

NgeJavaScript

Fowunela i-modal ene-id myModalngomgca omnye weJavaScript:

  1. $ ( '#myModal' ). imodeli ( iinketho )

Iinketho

Iinketho zinokugqithiswa ngeempawu zedatha okanye iJavaScript. Kuphawu lwedatha, faka igama lokhetho ku data-, njengakwi data-backdrop="".

Igama uhlobo ukungagqibeki inkcazelo
ngasemva boolean yinyani Ibandakanya i-modal-backdrop element. Kungenjalo, khankanya staticimeko yangasemva engayivaliyo imodal ngokucofa.
ikhibhodi boolean yinyani Ivala imodal xa iqhosha lokubaleka licofa
bonisa boolean yinyani Ibonisa imodali xa iqaliswa.
kude indlela bubuxoki

Ukuba i-url ekude inikezelwe, umxholo uya kulayishwa ngendlela yejQuery loadkwaye utofwe kwi .modal-body. Ukuba usebenzisa i-api yedatha, ungasebenzisa ngenye indlela hrefithegi ukukhankanya umthombo okude. Umzekelo woku uboniswe ngezantsi:

  1. <a data-toggle="modal" href="remote.html" data-target="#modal">click me</a>

Iindlela

.modal(iinketho)

Yenza umxholo wakho ube yimodali. Yamkela iinketho ozikhethelayo object.

  1. $ ( '#myModal' ). imodeli ({
  2. keyboard : bubuxoki
  3. })

.modal('tshintsha')

Yenza imodal ngesandla.

  1. $ ( '#myModal' ). imodali ( 'tshintsha' )

.modal('umboniso')

Ivula imodali ngesandla.

  1. $ ( '#myModal' ). imodali ( 'bonisa' )

.modal('fihla')

Ufihla imodali ngesandla.

  1. $ ( '#myModal' ). imodali ( 'fihla' )

Iziganeko

Iklasi ye-modal ye-Bootstrap iveza iminyhadala embalwa yokuqhagamshelwa ekusebenzeni kwe-modal.

Isiganeko Inkcazo
bonisa Esi siganeko sivutha ngokukhawuleza xa showkubizwa indlela yomzekelo.
ibonisiwe Esi siganeko sigxothwa xa i-modal yenziwe yabonakala kumsebenzisi (iya kulinda iinguqu ze-css ukuba zigqibe).
fihla Esi siganeko sigxothwa ngokukhawuleza xa hideindlela yomzekelo ibiziwe.
efihliweyo Esi siganeko siyagxothwa xa i-modal igqibile ukufihlwa kumsebenzisi (iya kulinda i-css transitions ukuba igqibe).
  1. $ ( '#myModal' ). kwi ( 'ifihliwe' , umsebenzi () {
  2. // Yenza into…
  3. })

Umzekelo kwi-navbar

I-plugin yeScrollSpy yeyokuhlaziya ngokuzenzekelayo iithagethi ze-nav ngokusekelwe kwindawo yokuskrola. Skrolela indawo engezantsi kwe-navbar kwaye ubukele utshintsho lweklasi esebenzayo. Imiba esezantsi yokwehla nayo iya kuphawulwa.

@fat

Ad leggings keytar, brunch id art party dolor labore. I-Pitchfork ngonyaka enim lo-fi ngaphambi kokuba bathengise yonke into. Tumblr ifama-to-itheyibhile amalungelo ibhayisekile nantoni na. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Ijezi kaCosby ilomo yejean ezimfutshane, williamsburg hoodie minim qui mhlawumbi awuzange uve ngazo et cardigan trust fund culpa biodiesel wes anderson aesthetic. UNihil une tattoo accsamus, cred irony biodiesel keffiyeh artisan ullamco consequat.

@mdo

Veniam marfa amadevu ngesityibiliki, adipisicing fugiat velit pitchfork iindevu. Freegan iindevu aliqua cupidatat mcsweeney's vero. Cupidatat ezine loko nisi, ea helvetica nulla carles. I-Tattooed cosby sweater ilori yokutya, i-mcsweeney's quis non freegan vinyl. Lo-fi wes anderson +1 sartorial. Carles non aesthetic exercitation quis gentrify. EBrooklyn adipisicing craft beer vice keytar deserunt.

Nye

Occaecat commodo aliqua deelectus. Fap craft beer deserunt skateboard ea. Amalungelo ebhayisekile eLomo adipisicing banh mi, velit ea sunt kwinqanaba elilandelayo locavore ikofu enemvelaphi eyodwa e magna veniam. Ubomi obuphezulu id vinyl, echo park consequat quis aliquip banh mi pitchfork. Vero VHS est adipisicing. Consectetur nisi DIY minim messenger bag. Cred ex in, ezinzileyo deelectus consectetur fanny pack iphone.

Mbini

In incididunt echo park, officia deserunt mcsweeney's proident master cleanse thundercats sapiente veniam. Excepteur VHS elit, proident shoreditch +1 biodiesel laborum craft beer. Single-origin coffee wayfarers irure four loko, cupidatat terry richardson master cleanse. Assumenda you probably haven't heard of them art party fanny pack, tattooed nulla cardigan tempor ad. Proident wolf nesciunt sartorial keffiyeh eu banh mi sustainable. Elit wolf voluptate, lo-fi ea portland before they sold out four loko. Locavore enim nostrud mlkshk brooklyn nesciunt.

three

Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.

Keytar twee blog, culpa isithunywa bag marfa nantoni na ilori yokutya deelectus. Sapiente synth id guessnda. Locavore sed helvetica cliche irony, thundercats mhlawumbi awuzange uve ngazo consequat hoodie gluten-free lo-fi fap aliquip. Labore elit placeat phambi kokuba bathengise, terry richardson proident brunch nesciunt quis cosby sweater pariatur keffiyeh ut helvetica artisan. Cardigan craft beer seitan readymade velit. VHS chambray laboris tempor veniam. Anim mollit minim commodo ullamco thundercats.


Ukusetyenziswa

Ngeempawu zedatha

Ukongeza ngokulula isimilo sokuskrola kulawulo lwakho lwebar engaphezulu, yongeza data-spy="scroll"nje kwinto ofuna ukuyihlola (ubukhulu becala lo iyakuba ngumzimba) kwaye data-target=".navbar"ukhethe ukuba yeyiphi nav oza kuyisebenzisa. Uya kufuna ukusebenzisa iscrollspy kunye .navnecandelo.

  1. <body data-spy = "scroll" data-target = ".navbar" > ... </ body>

NgeJavaScript

Fowunela iscrollspy ngeJavaScript:

  1. $ ( '#navbar' ). skrola ()
Iintloko phezulu! Unxulumano lwebar yeNavbar kufuneka lube nethagethi ye-id enokusombululeka. Umzekelo, <a href="#home">home</a>kufuneka ihambelane nento ekwidom efana <div id="home"></div>.

Iindlela

.skrola('hlaziya')

Xa usebenzisa i-scrollspy ngokudibanisa okanye ukususa izinto kwi-DOM, kuya kufuneka ufowunele indlela yokuhlaziya ngolu hlobo:

  1. $ ( '[data-spy="scroll"]' ). Nganye ( umsebenzi () {
  2. var $ hlola = $ ( le ). scrollspy ( 'hlaziya' )
  3. });

Iinketho

Iinketho zinokugqithiswa ngeempawu zedatha okanye iJavaScript. Kuphawu lwedatha, faka igama lokhetho ku data-, njengakwi data-offset="".

Igama uhlobo ukungagqibeki inkcazelo
i-offset inani 10 Iipikseli zokulinganisa ukusuka phezulu xa ubala indawo yokuskrola.

Iziganeko

Isiganeko Inkcazo
vula Esi siganeko sivutha nanini na into entsha ivuliwe yi-scrollspy.

Iithebhu zemizekelo

Yongeza ngokukhawuleza, ukusebenza kwethebhu eguquguqukayo kwi-transiton ngokusebenzisa iipaneli zomxholo wasekhaya, nangeemenyu ezihlayo.

Idenim ekrwada mhlawumbi awuzange uve ngabo ibhulukhwe yejean yaseAustin. Nesciunt tofu stumptown aliqua, retro synth master coca. Amadevu cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Ijezi yeCosby eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american iimpahla, butcher voluptate nisi qui.

Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.


Ukusetyenziswa

Yenza iithebhu ezinokubakho ngeJavaScript (ithebhu nganye kufuneka ivulwe ngokwayo):

  1. $ ( '#myTab a' ). cofa ( umsebenzi ( e ) {
  2. e . preventDefault ();
  3. $ ( oku ). ithebhu ( 'bonisa' );
  4. })

Unokwenza ithebhu nganye isebenze ngeendlela ezininzi:

  1. $ ( '#myTab a[href="#profile"]' ). ithebhu ( 'bonisa' ); // Khetha isithuba ngegama
  2. $ ( '#myTab a:first' ). ithebhu ( 'bonisa' ); // Khetha ithebhu yokuqala
  3. $ ( '#myTab a:last' ). ithebhu ( 'bonisa' ); // Khetha isithuba sokugqibela
  4. $ ( '#myTab li:eq(2) a' ). ithebhu ( 'bonisa' ); // Khetha ithebhu yesithathu (0-isalathisi)

IMarkup

Unokwenza ithebhu okanye ujongo lwepilisi ngaphandle kokubhala nayiphi na iJavaScript ngokuchaza ngokulula data-toggle="tab"okanye data-toggle="pill"kwinto. Ukongeza i navkunye nav-tabsneeklasi kwithebhu ulkuya kusebenzisa isimbo se-Bootstrap tab.

  1. <ul class = "nav nav-tabs" >
  2. <li><a href = "#ikhaya" data-toggle = "tab"> Ekhaya </a> < /li>
  3. <li><a href = "#profile" data-toggle = "tab"> Inkangeleko yesimo </a></li >
  4. <li><a href = "# imiyalezo" data-toggle = "tab"> Imiyalezo </a> < /li>
  5. <li><a href = "#settings" data-toggle = "tab"> Useto </a> </li>
  6. </ul>

Iindlela

$().tab

Yenza isiqalelo sethebhu kunye nesiqulatho sisebenze. Isithuba kufuneka sibenendawo data-targetokanye indawo hrefyesikhongozeli kwiDOM.

  1. <ul class = "nav nav-tabs" id = "myTab" >
  2. <li iklasi = "esebenzayo" > <a href = "#ikhaya"> Ekhaya </a></li>
  3. <li><a href = "#profile"> Inkangeleko yesimo </a></li>
  4. <li><a href = "#imiyalezo"> Imiyalezo </a> </li>
  5. <li><a href = "#iisetingi"> Useto </a> </li>
  6. </ul>
  7.  
  8. <div class = "ithebhu-umxholo" >
  9. <div class = "i-tab-pane esebenzayo" id = "ikhaya" > ... </div>
  10. <div class = "i-tab-pane" id = "iprofayile" > ... </div>
  11. <div class = "i-tab-pane" id = "imiyalezo" > ... </div>
  12. <div class = "i-tab-pane" id = "iisetingi" > ... </div>
  13. </ div>
  14.  
  15. <script>
  16. $ ( umsebenzi () {
  17. $ ( '#myTab a:last' ). ithebhu ( 'bonisa' );
  18. })
  19. </script>

Iziganeko

Isiganeko Inkcazo
bonisa Esi siganeko sivutha kumboniso wethebhu, kodwa ngaphambi kokuba ithebhu entsha iboniswe. Sebenzisa event.targetkunye event.relatedTargetnokujolisa isithuba esisebenzayo kunye nesithuba sangaphambili esisebenzayo (ukuba sikhona) ngokulandelelanayo.
ibonisiwe Esi siganeko sitshisa kwi-tab show emva kokuba ithebhu ibonisiwe. Sebenzisa event.targetkunye event.relatedTargetnokujolisa isithuba esisebenzayo kunye nesithuba sangaphambili esisebenzayo (ukuba sikhona) ngokulandelelanayo.
  1. $ ( 'a[data-toggle="tab"]' ). kwi ( 'ibonisiwe' , umsebenzi ( e ) {
  2. e . ekujoliswe kuko // ithebhu evuliwe
  3. e . relatedTarget // ithebhu yangaphambili
  4. })

Imizekelo

Iphefumlelwe yi-plugin egqwesileyo ye-jQuery.tipsy ebhalwe nguJason Frame; Iingcebiso zesixhobo luguqulelo oluhlaziyiweyo, olungathembekanga kwimifanekiso, sebenzisa i-CSS3 yoopopayi, kunye neempawu zedatha zogcino lwesihloko sendawo.

Hambisa ngaphezulu kwezi linki zingezantsi ukuze ubone iingcebiso zesixhobo:

Iibhulukhwe eziqinileyo kwinqanaba elilandelayo keffiyeh mhlawumbi awuzange uve ngazo. Photo booth iindevu ekrwada idenim letterpress vegan messenger bag stumptown. Ifama-to-itheyibhile seitan, i-mcsweeney's fixie ezinzileyo iquinoa ye-8-bit yaseMelika isambatho sine - terry richardson vinyl chambray. Iindevu stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray. Igcisa elihlekisayo ngokwenene whatever keytar , i-scenar farm-to-table banksy Austin twitter handle freegan cred krwada idenim enye-origin ikofu viral.

Iindlela ezine


Ukusetyenziswa

Qalisa ingcebiso yesixhobo ngeJavaScript:

  1. $ ( '#example' ). incam yesixhobo ( iinketho )

Iinketho

Iinketho zinokugqithiswa ngeempawu zedatha okanye iJavaScript. Kuphawu lwedatha, faka igama lokhetho ku data-, njengakwi data-animation="".

Igama uhlobo ukungagqibeki inkcazelo
oopopayi boolean yinyani sebenzisa i-css fade inguqu kwisixhobo sesixhobo
html boolean bubuxoki Faka i-html kwincam yesixhobo. Ukuba ayiyonyani, indlela yejquery textizakusetyenziswa ukufaka umxholo kwi dom. Sebenzisa umbhalo ukuba unexhala malunga nohlaselo lwe-XSS.
ukubekwa umtya|umsebenzi 'phezulu' indlela yokubeka inqaku lesixhobo - phezulu | emazantsi | ekhohlo | kunene
umkhethi umtya bubuxoki Ukuba umkhethi unikiwe, izixhobo zesixhobo ziya kunikezelwa kwiithagethi ezichaziweyo.
isihloko umtya | umsebenzi '' ixabiso lesihloko esimiselweyo ukuba `isihloko` ithegi ayikho
ukuxhokonxa umtya 'hamba phezulu' how tooltip is triggered - click | hover | focus | manual
delay number | object 0

delay showing and hiding the tooltip (ms) - does not apply to manual trigger type

If a number is supplied, delay is applied to both hide/show

Object structure is: delay: { show: 500, hide: 100 }

Heads up! Options for individual tooltips can alternatively be specified through the use of data attributes.

Markup

For performance reasons, the Tooltip and Popover data-apis are opt in. If you would like to use them just specify a selector option.

  1. <a href="#" rel="tooltip" title="first tooltip">hover over me</a>

Methods

$().tooltip(options)

Attaches a tooltip handler to an element collection.

.tooltip('show')

Reveals an element's tooltip.

  1. $('#element').tooltip('show')

.tooltip('hide')

Hides an element's tooltip.

  1. $('#element').tooltip('hide')

.tooltip('toggle')

Toggles an element's tooltip.

  1. $('#element').tooltip('toggle')

.tooltip('destroy')

Hides and destroys an element's tooltip.

  1. $('#element').tooltip('destroy')

Examples

Add small overlays of content, like those on the iPad, to any element for housing secondary information. Hover over the button to trigger the popover. Requires Tooltip to be included.

Static popover

Four options are available: top, right, bottom, and left aligned.

Popover top

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Popover right

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Popover bottom

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Popover left

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

No markup shown as popovers are generated from JavaScript and content within a data attribute.

Live demo

Four directions


Usage

Enable popovers via JavaScript:

  1. $('#example').popover(options)

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-animation="".

Name type default description
animation boolean true apply a css fade transition to the tooltip
html boolean false Insert html into the popover. If false, jquery's text method will be used to insert content into the dom. Use text if you're worried about XSS attacks.
placement string|function 'right' how to position the popover - top | bottom | left | right
selector string false if a selector is provided, tooltip objects will be delegated to the specified targets
trigger string 'click' how popover is triggered - click | hover | focus | manual
title string | function '' default title value if `title` attribute isn't present
content string | function '' default content value if `data-content` attribute isn't present
delay number | object 0

delay showing and hiding the popover (ms) - does not apply to manual trigger type

If a number is supplied, delay is applied to both hide/show

Object structure is: delay: { show: 500, hide: 100 }

Heads up! Options for individual popovers can alternatively be specified through the use of data attributes.

Markup

For performance reasons, the Tooltip and Popover data-apis are opt in. If you would like to use them just specify a selector option.

Methods

$().popover(options)

Initializes popovers for an element collection.

.popover('show')

Reveals an elements popover.

  1. $('#element').popover('show')

.popover('hide')

Hides an elements popover.

  1. $('#element').popover('hide')

.popover('toggle')

Toggles an elements popover.

  1. $('#element').popover('toggle')

.popover('destroy')

Hides and destroys an element's popover.

  1. $('#element').popover('destroy')

Example alerts

Add dismiss functionality to all alert messages with this plugin.

Holy guacamole! Best check yo self, you're not looking too good.

Oh snap! You got an error!

Change this and that and try again. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum.

Take this action Or do this


Usage

Enable dismissal of an alert via JavaScript:

  1. $(".alert").alert()

Markup

Just add data-dismiss="alert" to your close button to automatically give an alert close functionality.

  1. <a class="close" data-dismiss="alert" href="#">&times;</a>

Methods

$().alert()

Wraps all alerts with close functionality. To have your alerts animate out when closed, make sure they have the .fade and .in class already applied to them.

.alert('close')

Closes an alert.

  1. $(".alert").alert('close')

Events

Bootstrap's alert class exposes a few events for hooking into alert functionality.

Event Description
close This event fires immediately when the close instance method is called.
closed This event is fired when the alert has been closed (will wait for css transitions to complete).
  1. $('#my-alert').bind('closed', function () {
  2. // do something…
  3. })

Example uses

Do more with buttons. Control button states or create groups of buttons for more components like toolbars.

Stateful

Add data-loading-text="Loading..." to use a loading state on a button.

  1. <button type="button" class="btn btn-primary" data-loading-text="Loading...">Loading state</button>

Single toggle

Add data-toggle="button" to activate toggling on a single button.

  1. <button type="button" class="btn" data-toggle="button">Single Toggle</button>

Checkbox

Add data-toggle="buttons-checkbox" for checkbox style toggling on btn-group.

  1. <div class="btn-group" data-toggle="buttons-checkbox">
  2. <button type="button" class="btn">Left</button>
  3. <button type="button" class="btn">Middle</button>
  4. <button type="button" class="btn">Right</button>
  5. </div>

Radio

Add data-toggle="buttons-radio" for radio style toggling on btn-group.

  1. <div class="btn-group" data-toggle="buttons-radio">
  2. <button type="button" class="btn">Left</button>
  3. <button type="button" class="btn">Middle</button>
  4. <button type="button" class="btn">Right</button>
  5. </div>

Usage

Enable buttons via JavaScript:

  1. $('.nav-tabs').button()

Markup

Data attributes are integral to the button plugin. Check out the example code below for the various markup types.

Options

None

Methods

$().button('toggle')

Toggles push state. Gives the button the appearance that it has been activated.

Heads up! You can enable auto toggling of a button by using the data-toggle attribute.
  1. <button type="button" class="btn" data-toggle="button" ></button>

$().button('loading')

Sets button state to loading - disables button and swaps text to loading text. Loading text should be defined on the button element using the data attribute data-loading-text.

  1. <button type="button" class="btn" data-loading-text="loading stuff..." >...</button>
Heads up! Firefox persists the disabled state across page loads. A workaround for this is to use autocomplete="off".

$().button('reset')

Resets button state - swaps text to original text.

$().button(string)

Resets button state - swaps text to any data defined text state.

  1. <button type="button" class="btn" data-complete-text="finished!" >...</button>
  2. <script>
  3. $('.btn').button('complete')
  4. </script>

About

Get base styles and flexible support for collapsible components like accordions and navigation.

* Requires the Transitions plugin to be included.

Example accordion

Using the collapse plugin, we built a simple accordion style widget:

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
  1. <div class="accordion" id="accordion2">
  2. <div class="accordion-group">
  3. <div class="accordion-heading">
  4. <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
  5. Collapsible Group Item #1
  6. </a>
  7. </div>
  8. <div id="collapseOne" class="accordion-body collapse in">
  9. <div class="accordion-inner">
  10. Anim pariatur cliche...
  11. </div>
  12. </div>
  13. </div>
  14. <div class="accordion-group">
  15. <div class="accordion-heading">
  16. <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
  17. Collapsible Group Item #2
  18. </a>
  19. </div>
  20. <div id="collapseTwo" class="accordion-body collapse">
  21. <div class="accordion-inner">
  22. Anim pariatur cliche...
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. ...

You can also use the plugin without the accordion markup. Make a button toggle the expanding and collapsing of another element.

  1. <button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo">
  2. simple collapsible
  3. </button>
  4.  
  5. <div id="demo" class="collapse in"></div>

Usage

Via data attributes

Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element. The data-target attribute accepts a css selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class in.

To add accordion-like group management to a collapsible control, add the data attribute data-parent="#selector". Refer to the demo to see this in action.

Via JavaScript

Enable manually with:

  1. $(".collapse").collapse()

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-parent="".

Name type default description
parent selector false If selector then all collapsible elements under the specified parent will be closed when this collapsible item is shown. (similar to traditional accordion behavior)
toggle boolean true Toggles the collapsible element on invocation

Methods

.collapse(options)

Activates your content as a collapsible element. Accepts an optional options object.

  1. $('#myCollapsible').collapse({
  2. toggle: false
  3. })

.collapse('toggle')

Toggles a collapsible element to shown or hidden.

.collapse('show')

Shows a collapsible element.

.collapse('hide')

Hides a collapsible element.

Events

Bootstrap's collapse class exposes a few events for hooking into collapse functionality.

Event Description
show This event fires immediately when the show instance method is called.
shown This event is fired when a collapse element has been made visible to the user (will wait for css transitions to complete).
hide This event is fired immediately when the hide method has been called.
hidden This event is fired when a collapse element has been hidden from the user (will wait for css transitions to complete).
  1. $('#myCollapsible').on('hidden', function () {
  2. // do something…
  3. })

Example

A basic, easily extended plugin for quickly creating elegant typeaheads with any form text input.

  1. <input type="text" data-provide="typeahead">

Usage

Via data attributes

Add data attributes to register an element with typeahead functionality as shown in the example above.

Via JavaScript

Call the typeahead manually with:

  1. $('.typeahead').typeahead()

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-source="".

Name type default description
source array, function [ ] The data source to query against. May be an array of strings or a function. The function is passed two arguments, the query value in the input field and the process callback. The function may be used synchronously by returning the data source directly or asynchronously via the process callback's single argument.
items number 8 The max number of items to display in the dropdown.
minLength number 1 The minimum character length needed before triggering autocomplete suggestions
matcher function case insensitive The method used to determine if a query matches an item. Accepts a single argument, the item against which to test the query. Access the current query with this.query. Return a boolean true if query is a match.
sorter function exact match,
case sensitive,
case insensitive
Method used to sort autocomplete results. Accepts a single argument items and has the scope of the typeahead instance. Reference the current query with this.query.
updater function returns selected item The method used to return selected item. Accepts a single argument, the item and has the scope of the typeahead instance.
highlighter function highlights all default matches Method used to highlight autocomplete results. Accepts a single argument item and has the scope of the typeahead instance. Should return html.

Methods

.typeahead(options)

Initializes an input with a typeahead.

Example

The subnavigation on the left is a live demo of the affix plugin.


Usage

Via data attributes

To easily add affix behavior to any element, just add data-spy="affix" to the element you want to spy on. Then use offsets to define when to toggle the pinning of an element on and off.

  1. <div data-spy="affix" data-offset-top="200">...</div>
Heads up! You must manage the position of a pinned element and the behavior of its immediate parent. Position is controlled by affix, affix-top, and affix-bottom. Remember to check for a potentially collapsed parent when the affix kicks in as it's removing content from the normal flow of the page.

Via JavaScript

Call the affix plugin via JavaScript:

  1. $('#navbar').affix()

Methods

.affix('refresh')

When using affix in conjunction with adding or removing of elements from the DOM, you'll want to call the refresh method:

  1. $('[data-spy="affix"]').each(function () {
  2. $(this).affix('refresh')
  3. });

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-offset-top="200".

Name type default description
offset number | function | object 10 Iipixels zokulinganisa ukusuka kwiscreen xa ubala indawo yokuskrola. Ukuba inani elinye linikezelwe, i-offset iya kusetyenziswa kumacala omabini aphezulu nasekhohlo. Ukumamela isalathiso esinye, okanye ii-offsets ezininzi ezahlukeneyo, bonelela nje ngento offset: { x: 10 }. Sebenzisa umsebenzi xa ufuna ukubonelela ngokuguquguqukayo kwi-offset (iluncedo kuyilo oluthile oluphendulayo).