-1

Can you please take a look at this DEMO and let me know how I can use jquery to scroll to the selected row or animate that row to the middle of the scrolled div sc?

Here is the code:

<div id="sc">
    <table id="mytable"></table>
</div>
<button class="25">Scrool to 25</button>
<button class="75">Scrool to 75</button>
<button class="125">Scrool to 125</button>
<button class="199">Scrool to 199</button>
<button class="0">Scrool to 0</button>
<script>
$(document).ready(function () {
    for (var i = 0; i < 200; i++) {
     $('#mytable').append('<tr class=' + i + '><td>This is Row' + i + ' </td></tr>');
     $("#125").click(function() {
     $('#sc').animate({
    scrollTop: $("#sc").offset().top}, 2000);
 });
      }
});
<script>
user3162145
  • 101
  • 2
  • 6

1 Answers1

1

You may also used named anchors <a name="row10">...</a> and in your anchor tag just refer to the #tag like:

<a href="#row10">...</a>

Simplistic approach, should work for you unless you want some fancy animation and other stuff.

Vivek Jain
  • 3,703
  • 6
  • 26
  • 45