javascript.html 100 KB
Newer Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
    <p>Cycles the carousel to a particular frame (0 based, similar to an array).</p>

    <h4>.carousel('prev')</h4>
    <p>Cycles to the previous item.</p>

    <h4>.carousel('next')</h4>
    <p>Cycles to the next item.</p>

    <h3>Events</h3>
    <p>Bootstrap's carousel class exposes two events for hooking into carousel functionality.</p>
2011
    <div class="table-responsive">
2012
2013
2014
2015
2016
2017
2018
2019
2020
      <table class="table table-bordered table-striped">
        <thead>
         <tr>
           <th style="width: 150px;">Event Type</th>
           <th>Description</th>
         </tr>
        </thead>
        <tbody>
         <tr>
Jacob Thornton's avatar
Jacob Thornton committed
2021
           <td>slide.bs.carousel</td>
2022
2023
2024
           <td>This event fires immediately when the <code>slide</code> instance method is invoked.</td>
         </tr>
         <tr>
Jacob Thornton's avatar
Jacob Thornton committed
2025
           <td>slid.bs.carousel</td>
2026
2027
2028
2029
           <td>This event is fired when the carousel has completed its slide transition.</td>
         </tr>
        </tbody>
      </table>
2030
    </div><!-- /.table-responsive -->
2031
{% highlight js %}
fat's avatar
fat committed
2032
2033
2034
2035
$('#myCarousel').on('slide.bs.carousel', function () {
  // do something…
})
{% endhighlight %}
2036
  </div>
Mark Otto's avatar
Mark Otto committed
2037
2038
2039



2040
2041
2042
2043
2044
2045
  <!-- Affix
  ================================================== -->
  <div class="bs-docs-section">
    <div class="page-header">
      <h1 id="affix">Affix <small>affix.js</small></h1>
    </div>
Mark Otto's avatar
Mark Otto committed
2046

2047
2048
    <h2 id="affix-examples">Example</h2>
    <p>The subnavigation on the left is a live demo of the affix plugin.</p>
Mark Otto's avatar
Mark Otto committed
2049

2050
    <hr class="bs-docs-separator">
Mark Otto's avatar
Mark Otto committed
2051

2052
    <h2 id="affix-usage">Usage</h2>
2053
2054
2055
2056
2057
2058
    <p>Use the affix plugin via data attributes or manually with your own JavaScript. <strong>In both situations, you must provide CSS for the positioning of your content.</strong></p>

    <h3>Positioning via CSS</h3>
    <p>The affix plugin toggles between three classes, each representing a particular state: <code>.affix</code>, <code>.affix-top</code>, and <code>.affix-bottom</code>. You must provide the styles for these classes yourself (independent of this plugin) to handle the actual positions.</p>
    <p>Here's how the affix plugin works:</p>
    <ol>
Chris Rebert's avatar
Chris Rebert committed
2059
      <li>To start, the plugin adds <code>.affix-top</code> to indicate the element is in its top-most position. At this point no CSS positioning is required.</li>
2060
      <li>Scrolling past the element you want affixed should trigger the actual affixing. This is where <code>.affix</code> replaces <code>.affix-top</code> and sets <code>position: fixed;</code> (provided by Bootstrap's code CSS).</li>
kostyatretyak's avatar
kostyatretyak committed
2061
      <li>If a bottom offset is defined, scrolling past that should replace <code>.affix</code> with <code>.affix-bottom</code>. Since offsets are optional, setting one requires you to set the appropriate CSS. In this case, add <code>position: absolute;</code> when necessary. The plugin uses the data attribute or JavaScript option to determine where to position the element from there.</li>
2062
2063
    </ol>
    <p>Follow the above steps to set your CSS for either of the usage options below.</p>
Mark Otto's avatar
Mark Otto committed
2064

2065
    <h3>Via data attributes</h3>
2066
    <p>To easily add affix behavior to any element, just add <code>data-spy="affix"</code> to the element you want to spy on. Use offsets to define when to toggle the pinning of an element.</p>
Mark Otto's avatar
Mark Otto committed
2067
2068

{% highlight html %}
2069
2070
2071
<div data-spy="affix" data-offset-top="60" data-offset-bottom="200">
  ...
</div>
Mark Otto's avatar
Mark Otto committed
2072
2073
{% endhighlight %}

2074
2075
    <h3>Via JavaScript</h3>
    <p>Call the affix plugin via JavaScript:</p>
Mark Otto's avatar
Mark Otto committed
2076
{% highlight js %}
fat's avatar
fat committed
2077
2078
2079
2080
2081
2082
2083
2084
  $('#myAffix').affix({
    offset: {
      top: 100
    , bottom: function () {
        return (this.bottom = $('.bs-footer').outerHeight(true))
      }
    }
  })
Mark Otto's avatar
Mark Otto committed
2085
2086
2087
{% endhighlight %}


2088
2089
2090
    <h3>Options</h3>
    <p>Options can be passed via data attributes or JavaScript. For data attributes, append the option name to <code>data-</code>, as in <code>data-offset-top="200"</code>.</p>

2091
    <div class="table-responsive">
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
      <table class="table table-bordered table-striped">
        <thead>
         <tr>
           <th style="width: 100px;">Name</th>
           <th style="width: 100px;">type</th>
           <th style="width: 50px;">default</th>
           <th>description</th>
         </tr>
        </thead>
        <tbody>
         <tr>
           <td>offset</td>
           <td>number | function | object</td>
           <td>10</td>
fat's avatar
fat committed
2106
           <td>Pixels to offset from screen when calculating position of scroll. If a single number is provided, the offset will be applied in both top and bottom directions. To provide a unique, bottom and top offset just provide an object <code>offset: { top: 10 }</code> or <code>offset: { top: 10, bottom: 5 }</code>. Use a function when you need to dynamically calculate an offset.</td>
2107
2108
2109
         </tr>
        </tbody>
      </table>
2110
    </div><!-- /.table-responsive -->
2111

fat's avatar
fat committed
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151

    <h3>Events</h3>
    <p>Bootstrap's affix class exposes a few events for hooking into affix functionality.</p>
    <div class="table-responsive">
      <table class="table table-bordered table-striped">
        <thead>
          <tr>
            <th style="width: 150px;">Event Type</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>affix.bs.affix</td>
            <td>This event fires immediately before the element has been affixed.</td>
          </tr>
          <tr>
            <td>affixed.bs.affix</td>
            <td>This event is fired after the element has been affixed.</td>
          </tr>
          <tr>
            <td>affix-top.bs.affix</td>
            <td>This event fires immediately before the element has been affixed-top.</td>
          </tr>
          <tr>
            <td>affixed-top.bs.affix</td>
            <td>This event is fired after the element has been affixed-top.</td>
          </tr>
         <tr>
          <td>affix-bottom.bs.affix</td>
            <td>This event fires immediately before the element has been affixed-bottom.</td>
          </tr>
          <tr>
            <td>affixed-bottom.bs.affix</td>
            <td>This event is fired after the element has been affixed-bottom.</td>
          </tr>
        </tbody>
      </table>
    </div><!-- /.table-responsive -->

2152
  </div>
For faster browsing, not all history is shown. View entire blame