跟踪HTML div中的滚动位置 [英] track a scroll position inside an HTML div
问题描述
我正在使用google visualization table
创建一个html
表,它启用了The header row remains fixed as the user scrolls.
I am using google visualization table
to create an html
table, and it enables The header row remains fixed as the user scrolls.
我的工作方式如下: http://jsfiddle.net/RjHMH/114/
我面临的问题是,当我单击row
展开表格时,它实际上是重新绘制了表格,因此scroll bar
始终位于表格的顶部.无论如何,单击后是否可以跟踪滚动条的当前位置,并在重新绘制表格时将其设置回原来的值?
The problem I am facing is that, when I click a row
to expand the table, it actually redraw the table, so that the scroll bar
will always be at the top of the table. Is there anyway I can track the current position of the scroll bar when I click, and set the value back when the table is redrawn?
如果它是DOM
的scroll bar
,我可以使用:
If it is a scroll bar
of the DOM
, I can use:
var pos = $('body').scrollTop();
table.draw(view, options);
window.scrollTo(0, pos);
然后如何跟踪div
内的滚动条?
Then how to track the scroll bar inside a div
?
推荐答案
document.getElementsByClassName("google-visualization-table")[0].children[0].onscroll = function(){
console.log(this.scrollTop); //check the number in console
}
关键是获取js中的div或使用jquery,然后您可以访问该div的scrollTop.
The key is to get the div in js, or use jquery, then you can visit the scrollTop of that div.
这篇关于跟踪HTML div中的滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!