Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / CSS / bootstrap / docs / _includes / js / scrollspy.html
1 <div class="bs-docs-section">
2   <h1 id="scrollspy" class="page-header">ScrollSpy <small>scrollspy.js</small></h1>
3
4   <h2 id="scrollspy-examples">Example in navbar</h2>
5   <p>The ScrollSpy plugin is for automatically updating nav targets based on scroll position. Scroll the area below the navbar and watch the active class change. The dropdown sub items will be highlighted as well.</p>
6   <div class="bs-example" data-example-id="embedded-scrollspy">
7     <nav id="navbar-example2" class="navbar navbar-default navbar-static">
8       <div class="container-fluid">
9         <div class="navbar-header">
10           <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target=".bs-example-js-navbar-scrollspy">
11             <span class="sr-only">Toggle navigation</span>
12             <span class="icon-bar"></span>
13             <span class="icon-bar"></span>
14             <span class="icon-bar"></span>
15           </button>
16           <a class="navbar-brand" href="#">Project Name</a>
17         </div>
18         <div class="collapse navbar-collapse bs-example-js-navbar-scrollspy">
19           <ul class="nav navbar-nav">
20             <li><a href="#fat">@fat</a></li>
21             <li><a href="#mdo">@mdo</a></li>
22             <li class="dropdown">
23               <a href="#" id="navbarDrop1" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
24               <ul class="dropdown-menu" role="menu" aria-labelledby="navbarDrop1">
25                 <li><a href="#one" tabindex="-1">one</a></li>
26                 <li><a href="#two" tabindex="-1">two</a></li>
27                 <li class="divider"></li>
28                 <li><a href="#three" tabindex="-1">three</a></li>
29               </ul>
30             </li>
31           </ul>
32         </div>
33       </div>
34     </nav>
35     <div data-spy="scroll" data-target="#navbar-example2" data-offset="0" class="scrollspy-example">
36       <h4 id="fat">@fat</h4>
37       <p>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.</p>
38       <h4 id="mdo">@mdo</h4>
39       <p>Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard. Freegan beard aliqua cupidatat mcsweeney's vero. Cupidatat four loko nisi, ea helvetica nulla carles. Tattooed cosby sweater food truck, mcsweeney's quis non freegan vinyl. Lo-fi wes anderson +1 sartorial. Carles non aesthetic exercitation quis gentrify. Brooklyn adipisicing craft beer vice keytar deserunt.</p>
40       <h4 id="one">one</h4>
41       <p>Occaecat commodo aliqua delectus. Fap craft beer deserunt skateboard ea. Lomo bicycle rights adipisicing banh mi, velit ea sunt next level locavore single-origin coffee in magna veniam. High life id vinyl, echo park consequat quis aliquip banh mi pitchfork. Vero VHS est adipisicing. Consectetur nisi DIY minim messenger bag. Cred ex in, sustainable delectus consectetur fanny pack iphone.</p>
42       <h4 id="two">two</h4>
43       <p>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.</p>
44       <h4 id="three">three</h4>
45       <p>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.</p>
46       <p>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.
47       </p>
48     </div>
49   </div><!-- /example -->
50
51
52   <h2 id="scrollspy-usage">Usage</h2>
53
54   <div class="bs-callout bs-callout-warning" id="callout-scrollspy-needs-nav">
55     <h4>Requires Bootstrap nav</h4>
56     <p>Scrollspy currently requires the use of a <a href="../components/#nav">Bootstrap nav component</a> for proper highlighting of active links.</p>
57   </div>
58   <div class="bs-callout bs-callout-danger" id="callout-scrollspy-target-ids">
59     <h4>Resolvable ID targets required</h4>
60     <p>Navbar links must have resolvable id targets. For example, a <code>&lt;a href="#home"&gt;home&lt;/a&gt;</code> must correspond to something in the DOM like <code>&lt;div id="home"&gt;&lt;/div&gt;</code>.</p>
61   </div>
62   <div class="bs-callout bs-callout-info" id="callout-scrollspy-invisible-targets">
63     <h4>Non-<code>:visible</code> target elements ignored</h4>
64     <p>Target elements that are not <a href="http://api.jquery.com/visible-selector/"><code>:visible</code> according to jQuery</a> will be ignored and their corresponding nav items will never be highlighted.</p>
65   </div>
66
67   <h3>Requires relative positioning</h3>
68   <p>No matter the implementation method, scrollspy requires the use of <code>position: relative;</code> on the element you're spying on. In most cases this is the <code>&lt;body&gt;</code>.</p>
69
70   <h3>Via data attributes</h3>
71   <p>To easily add scrollspy behavior to your topbar navigation, add <code>data-spy="scroll"</code> to the element you want to spy on (most typically this would be the <code>&lt;body&gt;</code>). Then add the <code>data-target</code> attribute with the ID or class of the parent element of any Bootstrap <code>.nav</code> component.</p>
72 {% highlight css %}
73 body {
74   position: relative;
75 }
76 {% endhighlight %}
77 {% highlight html %}
78 <body data-spy="scroll" data-target="#navbar-example">
79   ...
80   <div id="navbar-example">
81     <ul class="nav nav-tabs" role="tablist">
82       ...
83     </ul>
84   </div>
85   ...
86 </body>
87 {% endhighlight %}
88
89   <h3>Via JavaScript</h3>
90   <p>After adding <code>position: relative;</code> in your CSS, call the scrollspy via JavaScript:</p>
91 {% highlight js %}
92 $('body').scrollspy({ target: '#navbar-example' })
93 {% endhighlight %}
94
95
96   <h3 id="scrollspy-methods">Methods</h3>
97   <h4><code>.scrollspy('refresh')</code></h4>
98   <p>When using scrollspy in conjunction with adding or removing of elements from the DOM, you'll need to call the refresh method like so:</p>
99 {% highlight js %}
100 $('[data-spy="scroll"]').each(function () {
101   var $spy = $(this).scrollspy('refresh')
102 })
103 {% endhighlight %}
104
105
106   <h3 id="scrollspy-options">Options</h3>
107   <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=""</code>.</p>
108   <div class="table-responsive">
109     <table class="table table-bordered table-striped js-options-table">
110       <thead>
111        <tr>
112          <th>Name</th>
113          <th>type</th>
114          <th>default</th>
115          <th>description</th>
116        </tr>
117       </thead>
118       <tbody>
119        <tr>
120          <td>offset</td>
121          <td>number</td>
122          <td>10</td>
123          <td>Pixels to offset from top when calculating position of scroll.</td>
124        </tr>
125       </tbody>
126     </table>
127   </div><!-- ./bs-table-responsive -->
128
129   <h3 id="scrollspy-events">Events</h3>
130   <div class="table-responsive">
131     <table class="table table-bordered table-striped bs-events-table">
132       <thead>
133        <tr>
134          <th>Event Type</th>
135          <th>Description</th>
136        </tr>
137       </thead>
138       <tbody>
139        <tr>
140          <td>activate.bs.scrollspy</td>
141          <td>This event fires whenever a new item becomes activated by the scrollspy.</td>
142       </tr>
143       </tbody>
144     </table>
145   </div><!-- ./bs-table-responsive -->
146 {% highlight js %}
147 $('#myScrollspy').on('activate.bs.scrollspy', function () {
148   // do something…
149 })
150 {% endhighlight %}
151 </div>