scroll to element in a long div
I have a scrollable div that contains a table with many rows (100+).
I would like to be able to show the table row that contains the data I'm looking for via a jQuery filter.
I know the t开发者_高级运维able row id. How do I move the div down to the correct row?
Try:
document.getElementById(id).scrollIntoView(true);
It's part of the CSSOM View Module, it may not be supported in all browsers, but probably all you care about though.
Ooops missed the row in row id. If you have a reference to the table, then:
table.rows[rowId].scrollIntoView(true);
Try this:
$('html, body').scrollTop($('#rowId').offset().top);
If you want litte animation:
$('html, body').animate({
scrollTop: $("#rowId").offset().top
}, 2000); // 2000 is the duration of animation in milliseconds
精彩评论