I have a big table with vertical scroll bar. I would like to scroll to a specific line in this table using jQuery/Javascript.
Are there built-in methods to do this?
Here is a little example to play with.
div {
width: 100px;
height: 70px;
border: 1px solid blue;
overflow: auto;
}
<div>
<table id="my_table">
<tr id='row_1'><td>1</td></tr>
<tr id='row_2'><td>2</td></tr>
<tr id='row_3'><td>3</td></tr>
<tr id='row_4'><td>4</td></tr>
<tr id='row_5'><td>5</td></tr>
<tr id='row_6'><td>6</td></tr>
<tr id='row_7'><td>7</td></tr>
<tr id='row_8'><td>8</td></tr>
<tr id='row_9'><td>9</td></tr>
</table>
</div>
Dead simple. No plugins needed.
Here is a working example.
Documentation for
scrollTop
.You can scroll by jQuery and JavaScript Just need two element jQuery and this JavaScript code :
Best plugin I found was this gist.
Its not a plugin per say but it does the work of one, and it solved my problems. unfortunately it only works in FireFox. No idea why chrome doesn't like it/doesn't wanna run it.
EDIT: Meanwhile I managed to do it myself. No need for any plugins. Check out my gist:
Scroll element to center of container
To bring the element to the center of the container.
DEMO on CODEPEN
JS
HTML
css
It is not exact to the center but you will not recognice it on larger bigger elements.
I've always found the jQuery scrollTo plugin to be very useful for this. Play with the demos to see if it's for you.
Not sure why no one says the obvious, as there's a built in javascript
scrollTo
function:Reference.