I have a table inside of a div (it's overflow, so the browser renders a scrollbar). Using JavaScript, how do I move the scrollbar handle along the track to a position that corresponds to the location of a row in the table?
+--------------------------------------+
|100 | |
|101 | |
|102 | |
|103 | |
|104 | |
|105 This is a table that |---|
|106 has overflowed. | - | <-- I want to move this using JavaScript,
|107 |---| so that a specific row # is visible.
|108 | |
|109 | |
|110 | |
|111 | |
+--------------------------------------+
Если вы хотите использовать не способ jQuery , используйте свойство scrollTop
содержащейся таблицы.
Предположим, вы можете легко определить строку, которую хотите прокрутить, используя идентификатор вместе с содержащим
. Используйте offsetTop
элемента, к которому вы хотите прокрутить.
var container = document.getElementById('myContainingDiv');
var rowToScrollTo = document.getElementById('myRow');
container.scrollTop = rowToScrollTo.offsetTop;