Javascript bakeng sa Bootstrap

Tliša dikarolo tša Bootstrap bophelong-bjale ka di-plugin tše 12 tša jQuery tša tlwaelo.

Dihlogo godimo! Di-plugin ka moka tša javascript di nyaka phetolelo ya moragorago ya jQuery.

Mabapi le di-modal

A streamlined, empa tenyetsehang, nka ka setso javascript modal plugin le feela bonyane hlokahalang tshebetso le bohlale defaults.

Download faele ya

Mohlala wa static

Ka tlase ke statically e filwe modal.

Demo e phelang

Toggle a modal ka javascript ka ho tobetsa konopo e ka tlase. E tla thelela fase gomme ya fifala ka gare go tšwa godimo ga letlakala.

Thakgola mokgwa wa demo

Go diriša bootstrap-modal

Bitsa modal ka javascript:

  1. $ ( '#Modal ya ka' ). modal ( dikgetho ) .

Dikgetho

Leina mohuta hlokomologa tlhalošo
lemorago la ka morago boolean ya go swana nnete E akaretša elemente ya modal-backdrop
khiiboto ya boolean ya go swana nnete E tswalela modal ge senotlelo sa go tšhaba se tobetšwe

Go swaya

O ka tsenya tirišong di-modal letlakaleng la gago gabonolo ntle le go ngwala mola o tee wa javascript. E no beakanya data-toggle="modal"godimo ga elemente ya molaodi ka data-target="#foo"goba href="#foo"yeo e sepelelanago le id ya elemente ya modal, gomme ge e kgotla, e tla thoma modal ya gago.

Gape, go oketša dikgetho go mohlala wa gago wa modal, di akaretša fela bjalo ka dika tša tlaleletšo tša datha go e ka ba elemente ya taolo goba go swaya modal ka boyona.

  1. <a sehlopha = "btn" data-toggle = "modal" href = "#myModal" > Thoma Modal </a>
  1. <div sehlopha = "modal" >
  2. <div sehlopha = "modal-hlooho" >
  3. <a sehlopha = "tswalela" ya data-dismiss = "modal" > × </a>
  4. <h3> Hlogo ya modale </h3>
  5. </div> e
  6. <div sehlopha = "modal-mmele" >
  7. <p> Mmele o tee o mobotse... </p>
  8. </div> e
  9. <div sehlopha = "modal-footer" >
  10. <a href = "#" class = "btn btn-primary" > Boloka diphetogo </a>
  11. <a href = "#" sehlopha = "btn" > Tswala </a>
  12. </div> e
  13. </div> e
Dihlogo godimo! Ge e ba o nyaka gore modal ya gago e phele ka gare le ka ntle, e no oketša .fadesehlopha go .modalelemente (lebelela demo go bona se ka tiro) gomme o akaretše bootstrap-transition.js.

Mekgwa ya go šoma

.modal(dikgetho) .

E dira gore diteng tša gago di šome bjalo ka modal. E amogela dikgetho tša boikhethelo object.

  1. $ ( '#Modal ya ka' ). modal ({ ) .
  2. khiiboto : maaka
  3. }) .

.modal (' go fetola') .

Ka seatla e fetola modal.

  1. $ ( '#Modal ya ka' ). modal ( 'go fetola' ) .

.modal ('bontša') .

Ka letsoho bula e modal.

  1. $ ( '#Modal ya ka' ). modal ( 'bontša' ) .

.modal('pata') .

Ka letsoho pata e modal.

  1. $ ( '#Modal ya ka' ). modal ( 'pata' ) .

Ditiragalo

Bootstrap o modal sehlopha pepesa liketsahalo tse seng kae bakeng sa hooking ka modal tshebetso.

Tiragalo Tlhalošo
bontšha Tiragalo ye e thunya ka pela ge showmokgwa wa mohlala o bitšwa.
e bontšhitšwe Tiragalo ye e thuntšhwa ge modal e dirilwe gore e bonagale go mosediriši (e tla emela gore diphetogo tša css di phethe).
fihla Tiragalo ye e thuntšhwa ka pela ge hidemokgwa wa mohlala o biditšwe.
fihlilwe Tiragalo ye e thuntšhwa ge modal e feditše go utollwa go tšwa go mosediriši (e tla emela gore diphetogo tša css di phethe).
  1. $ ( '#Modal ya ka' ). ka ( 'e patiloeng' , mosebetsi () {
  2. // dira se sengwe...
  3. }) .

The ScrollSpy plugin ke bakeng sa ka tsela e iketsang ntjhafatsa nav diphetho thehiloeng scroll boemo.

Download faele ya

Mohlala navbar le scrollspy

Scroll lefelo le le lego ka mo tlase gomme o lebelele mpshafatšo ya go sepelasepela. Diaetheme tša ka fasana tša go theoga di tla hlaolwa gape. E leke!

@lekhura

Ad leggings keytar, brunch id bonono mokga dolor labore. Pitchfork yr enim lo-fi pele ba rekisa qui. Tumblr polasa-ho-tafoleng baesekele ditokelo eng kapa eng. Anim keffiyeh carles cardigan ya go swana le yona. Velit seitan mcsweeney o photo photo photo lephephe 3 phiri ngwedi irure. Cosby jesi lomo jean shorts, williamsburg hoodie minim qui mohlomong ha ua utloa ka bona et cardigan letlole la tšepo culpa biodiesel wes anderson botsebi. Nihil tattooed accusamus, cred kgegeo biodiesel keffiyeh mosebetsi oa matsoho ullamco consequat.

@mdo

Veniam marfa ditedu skateboard, adipisicing fugiat velit ditedu tša foroko ya pitchfork. Freegan ditedu aliqua cupidatat vero ya mcsweeney. Cupidatat ba bane loko nisi, ea helvetica nulla carles. Tattooed cosby jesi lijo teraka, mcsweeney o quis bao e seng freegan vinyl. Lo-fi wes anderson +1 seaparo sa go robala. Carles bao e seng botsebi boitšhidullo quis gentrify. Brooklyn adipisicing mesebetsi ea matsoho biri motlatsi keytar deserunt.

tee

Occaecat commodo ya go swana le ya go swana le ya delectus. Fap mesebetsi ea matsoho biri deserunt skateboard ea. Lomo baesekele ditokelo adipisicing banh mi, velit ea sunt boemo bo latelang locavore e le 'ngoe-tšimoloho kofi ka magna veniam. Bophelo bo phahameng id vinyl, echo phakeng consequat quis aliquip banh mi foroko ea pitchfork. Vero VHS est go godiša. Consectetur nisi DIY bonyane mokotla wa moromiwa. Cred ex ka, tšoarellang delectus consectetur fanny pakete iphone.

pedi

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 messenger bag marfa whatever delectus food truck. Sapiente synth id assumenda. Locavore sed helvetica cliche irony, thundercats you probably haven't heard of them consequat hoodie gluten-free lo-fi fap aliquip. Labore elit placeat before they sold out, 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.


Using bootstrap-scrollspy.js

Call the scrollspy via javascript:

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

Markup

To easily add scrollspy behavior to your topbar navigation, just add data-spy="scroll" to the element you want to spy on (most typically this would be the body).

  1. <body data-spy="scroll" >...</body>
Heads up! Navbar links must have resolvable id targets. For example, a <a href="#home">home</a> must correspond to something in the dom like <div id="home"></div>.

Options

Name type default description
offset number 10 Pixels to offset from top when calculating position of scroll.

This plugin adds quick, dynamic tab and pill functionality for transitioning through local content.

Download file

Example tabs

Click the tabs below to toggle between hidden panes, even via dropdown menus.

Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, 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.


Using bootstrap-tab.js

Enable tabbable tabs via javascript:

  1. $('#myTab').tab('show')

Markup

You can activate a tab or pill navigation without writing any javascript by simply specifying data-toggle="tab" or data-toggle="pill" on an element.

  1. <ul class="tabs">
  2. <li><a href="#home" data-toggle="tab">Home</a></li>
  3. <li><a href="#profile" data-toggle="tab">Profile</a></li>
  4. <li><a href="#messages" data-toggle="tab">Messages</a></li>
  5. <li><a href="#ettings" data-toggle="tab">Settings</a></li>
  6. </ul>

Methods

$().tab

Activates a tab element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the dom.

  1. <ul class="tabs">
  2. <li class="active"><a href="#home">Home</a></li>
  3. <li><a href="#profile">Profile</a></li>
  4. <li><a href="#messages">Messages</a></li>
  5. <li><a href="#settings">Settings</a></li>
  6. </ul>
  7.  
  8. <div class="tab-content">
  9. <div class="tab-pane active" id="home">...</div>
  10. <div class="tab-pane" id="profile">...</div>
  11. <div class="tab-pane" id="messages">...</div>
  12. <div class="tab-pane" id="settings">...</div>
  13. </div>
  14.  
  15. <script>
  16. $(function () {
  17. $('.tabs a:last').tab('show')
  18. })
  19. </script>

Events

Event Description
show This event fires on tab show, but before the new tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively.
shown This event fires on tab show after a tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively.
  1. $('a[data-toggle="tab"]').on('shown', function (e) {
  2. e.target // activated tab
  3. e.relatedTarget // previous tab
  4. })

About Tooltips

Inspired by the excellent jQuery.tipsy plugin written by Jason Frame; Tooltips are an updated version, which don't rely on images, uss css3 for animations, and data-attributes for local title storage.

Download file

Example use of Tooltips

Hover over the links below to see tooltips:

Tight pants next level keffiyeh you probably haven't heard of them. Photo booth beard raw denim letterpress vegan messenger bag stumptown. Farm-to-table seitan, mcsweeney's fixie sustainable quinoa 8-bit american apparel have a terry richardson vinyl chambray. Beard stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray. A really ironic artisan whatever keytar, scenester farm-to-table banksy Austin twitter handle freegan cred raw denim single-origin coffee viral.


Using bootstrap-tooltip.js

Trigger the tooltip via javascript:

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

Options

Name type default description
animation boolean true apply a css fade transition to the tooltip
placement string 'top' how to position the tooltip - top | bottom | left | right
selector string false If a selector is provided, tooltip objects will be delegated to the specified targets.
title string | function '' default title value if `title` tag isn't present
trigger string 'hover' how tooltip is triggered - hover | focus | manual
delay number | object 0

delay showing and hiding the tooltip (ms)

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.

Methods

$().tooltip(options)

Attaches a tooltip handler to an element collection.

.tooltip('show')

Reveals an elements tooltip.

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

.tooltip('hide')

Hides an elements tooltip.

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

.tooltip('toggle')

Toggles an elements tooltip.

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

About popovers

Add small overlays of content, like those on the iPad, to any element for housing secondary information.

* Requires Tooltip to be included

Download file

Example hover popover

Hover over the button to trigger the popover.


Using bootstrap-popover.js

Enable popovers via javascript:

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

Options

Name type default description
animation boolean true apply a css fade transition to the tooltip
placement string '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 'hover' how tooltip is triggered - 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)

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 the 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')

About alerts

The alert plugin is a tiny class for adding close functionality to alerts.

Download

Example alerts

The alerts plugin works on regular alert messages, and block messages.

× 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


Using bootstrap-alerts.js

Enable dismissal of an alert via javascript:

  1. $(".alert-message").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-message").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. })

About

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

Download file

Example uses

Use the buttons plugin for states and toggles.

Stateful
Single toggle
Checkbox
Radio

Using bootstrap-button.js

Enable buttons via javascript:

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

Markup

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

  1. <!-- Add data-toggle="button" to activate toggling on a single button -->
  2. <button class="btn" data-toggle="button">Single Toggle</button>
  3.  
  4. <!-- Add data-toggle="buttons-checkbox" for checkbox style toggling on btn-group -->
  5. <div class="btn-group" data-toggle="buttons-checkbox">
  6. <button class="btn">Left</button>
  7. <button class="btn">Middle</button>
  8. <button class="btn">Right</button>
  9. </div>
  10.  
  11. <!-- Add data-toggle="buttons-radio" for radio style toggling on btn-group -->
  12. <div class="btn-group" data-toggle="buttons-radio">
  13. <button class="btn">Left</button>
  14. <button class="btn">Middle</button>
  15. <button class="btn">Right</button>
  16. </div>

Methods

$().button('toggle')

Toggles push state. Gives btn the look that it's been activated.

Heads up! You can enable auto toggling of a button by using the data-toggle attribute.
  1. <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 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 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.

Download file

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.

Using bootstrap-collapse.js

Enable via javascript:

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

Options

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

Markup

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.

  1. <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>
Heads up! 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.

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. })

About

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

Download file

Example

Start typing in the field below to show the typeahead results.


Using bootstrap-typeahead.js

Call the typeahead via javascript:

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

Options

Name type default description
source array [ ] The data source to query against.
items number 8 The max number of items to display in the dropdown.
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.
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.

Markup

Add data attributes to register an element with typeahead functionality.

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

Methods

.typeahead(options)

Initializes an input with a typahead.