当表在带有jquery的可滚动div中时,如何使表行滚动到视图中?

时间:2015-10-02 19:11:08

标签: javascript jquery html

使用滚动的div:

data[pages][123][nav_hide]

如何将一行滚动到视图中,如:

<div id="PVwindow" style="overflow: scroll; max-width:800px; max-height:230px; float:left;">

这是非工作代码(它滚动但不在视图中):

<table id="PVtable"><tbody><tr>.....</tr>.....<tr id="scrollToViewP" style="background-color: #FFFF99;"><td>xxxx</td></tr></tbody></table>

这是jsfiddle working example that scrolls to the bottom

1 个答案:

答案 0 :(得分:0)

这是一个大部分时间都有效的解决方案(如80%),有时会滚动整个窗口以及div。

<script>
$( document ).ready(function() {

    var element = document.getElementById("scrollToViewP");
    element.scrollIntoView({block: "end", behavior: "smooth"});

});

我仍然希望有人会来并改善这一点。 (适用于FireFox和IE 11)