跟踪 HTML div 内的滚动位置

track a scroll position inside an HTML div

我正在使用 google visualization table 创建一个 html table,它启用 The header row remains fixed as the user scrolls.

我得到了这样的东西:http://jsfiddle.net/RjHMH/114/

我面临的问题是,当我单击 row 展开 table 时,它实际上重绘了 table,因此 scroll bar 将始终位于 table 的顶部。无论如何我可以在单击时跟踪滚动条的当前位置,并在重绘 table 时将值设置回来?

如果是DOMscroll bar,我可以用:

var pos = $('body').scrollTop();
table.draw(view, options);
window.scrollTo(0, pos);

那么如何在div里面跟踪滚动条呢?

var currentY = 0;

$(window).scroll(function () {
    currentY = $('selector').offset().top;
    console.log(currentY);
});

获得点击位置:

$(document).click(function () {
    currentY = $('selector').offset().top;
    console.log(currentY);

});
document.getElementsByClassName("google-visualization-table")[0].children[0].onscroll = function(){
    console.log(this.scrollTop); //check the number in console
}

关键是在js中获取div,或者使用jquery,然后就可以访问那个div的scrollTop了。