Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you want is <code>element.scrollIntoView();</code> this will scroll the browser window/div to make an element visible on the page.</p> <p>An example of this: <a href="http://jsfiddle.net/qG3rm/" rel="noreferrer">fiddle</a> link</p> <p><strong>Update</strong>: Added a more complete dynamic example.</p> <p><strong>CSS</strong></p> <pre><code>#container { overflow: auto; height: 50px; } .scrollto { color: blue; text-decoration: underline; cursor: pointer; } </code></pre> <p><strong>HTML</strong></p> <pre><code>&lt;span class="scrollto"&gt;a&lt;/span&gt; &lt;span class="scrollto"&gt;e&lt;/span&gt; &lt;span class="scrollto"&gt;i&lt;/span&gt; &lt;div id='container'&gt; &lt;div id="a"&gt;a&lt;/div&gt; &lt;div id="b"&gt;b&lt;/div&gt; &lt;div id="c"&gt;c&lt;/div&gt; &lt;div id="d"&gt;d&lt;/div&gt; &lt;div id="e"&gt;e&lt;/div&gt; &lt;div id="f"&gt;f&lt;/div&gt; &lt;div id="g"&gt;g&lt;/div&gt; &lt;div id="h"&gt;h&lt;/div&gt; &lt;div id="i"&gt;i&lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>JS</strong> </p> <pre><code>$('.scrollto').click(function() { $('#' + $(this).text()).get(0).scrollIntoView(); // or $('#' + $(this).text())[0].scrollIntoView(); }); </code></pre> <p>Basically in this example I created a small overflowed div causing it to have a scrollbar.</p> <p>I then use <code>id</code> anchors on div tags inside of it to label the different areas in it. I have a span outside the div to auto scroll to a certain anchor point inside the overflowed div when clicked.</p> <hr> <p><strong>@Wayne Smallman</strong>: As per the html code in your comment, this is what you would use</p> <pre><code>$('div#index ul li a').click(function() { $($(this).attr('href')).get(0).scrollIntoView(); }); </code></pre> <p><a href="http://jsfiddle.net/YEqYp/1/" rel="noreferrer">Fiddle Demo</a></p>
    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