Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recommend you check out the <a href="http://flesler.blogspot.com/2007/10/jqueryscrollto.html" rel="nofollow">scrollTo</a> plugin. Check out <a href="http://jsfiddle.net/Ruxwn/" rel="nofollow">this</a> example on jsFiddle.</p> <p><strong>Edit</strong><br> The key here is to use the <code>.offset().top</code> as the position to scroll to. This is the top of the element relative to the document (versus <code>.position().top</code> which would be relative to it's parent positioned container). You can also use the <a href="http://api.jquery.com/scrollTop/" rel="nofollow">built-in function</a> <code>.scrollTop(value)</code> if you don't want the scroll to be animated or you don't want to use the plug-in.</p> <p><strong>Edit 2</strong><br> Also, note you can use any selector you want for this part: <code>$('div:nth-child(1)').offset().top</code> In your case you'd want <code>$('div.content-body').offset().top</code>. Just remember that <code>.offset()</code> only returns the position of the first matched element.</p> <p><strong>Example</strong><br> <em>HTML</em></p> <pre><code>&lt;div id="first" style="background:red;"&gt; &lt;a href="#" class="go1"&gt;First&lt;/a&gt; &lt;a href="#" class="go2"&gt;Second&lt;/a&gt; &lt;a href="#" class="go3"&gt;Third&lt;/a&gt; &lt;/div&gt; &lt;div id="second" style="background:blue;"&gt; &lt;a href="#" class="go1"&gt;First&lt;/a&gt; &lt;a href="#" class="go2"&gt;Second&lt;/a&gt; &lt;a href="#" class="go3"&gt;Third&lt;/a&gt; &lt;/div&gt; &lt;div id="second" style="background:green;"&gt; &lt;a href="#" class="go1"&gt;First&lt;/a&gt; &lt;a href="#" class="go2"&gt;Second&lt;/a&gt; &lt;a href="#" class="go3"&gt;Third&lt;/a&gt; &lt;/div&gt; </code></pre> <p><em>CSS</em></p> <pre><code>div { height:1000px; } </code></pre> <p><em>JavaScript</em></p> <pre><code>$(function() { $('.go1').click(function() { $.scrollTo($('div:nth-child(1)').offset().top, 500); return false; }); $('.go2').click(function() { $.scrollTo($('div:nth-child(2)').offset().top, 500); return false; }); $('.go3').click(function() { $.scrollTo($('div:nth-child(3)').offset().top, 500); return false; }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload