Skip to content

Commit

Permalink
Fixes #12487: Document required use of position relative for scrollspy
Browse files Browse the repository at this point in the history
  • Loading branch information
mdo committed Mar 9, 2014
1 parent ce634a0 commit 4d870af
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/javascript.html
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,16 @@ <h4 id="three">three</h4>

<h2 id="scrollspy-usage">Usage</h2>

<h3>Requires relative positioning</h3>
<p>No matter the implementation method, scrollspy requires the use of <code>position: absolute;</code> on the element you're spying on. In most cases this is the <code>&lt;body&gt;</code>.</p>

This comment has been minimized.

Copy link
@juthilo

juthilo Mar 15, 2014

Collaborator

@mdo Did you intend to write <code>position: relative;</code> here?

This comment has been minimized.

Copy link
@mdo

mdo Mar 15, 2014

Author Member

Yup! Fixing.


<h3>Via data attributes</h3>
<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>
{% highlight css %}
body {
position: relative;
}
{% endhighlight %}
{% highlight html %}
<body data-spy="scroll" data-target=".navbar-example">
...
Expand All @@ -680,7 +688,7 @@ <h3>Via data attributes</h3>
{% endhighlight %}

<h3>Via JavaScript</h3>
<p>Call the scrollspy via JavaScript:</p>
<p>After adding <code>position: relative;</code> in your CSS, call the scrollspy via JavaScript:</p>
{% highlight js %}
$('body').scrollspy({ target: '.navbar-example' })
{% endhighlight %}
Expand Down

0 comments on commit 4d870af

Please sign in to comment.