[英]track a scroll position inside an HTML div
我正在使用google visualization table
来创建一个html
表,它使The header row remains fixed as the user scrolls.
我得到了这样的工作: http : //jsfiddle.net/RjHMH/114/
我面临的问题是,当我单击row
以展开表格时,它实际上是重新绘制表格,因此scroll bar
将始终位于表格的顶部。 无论如何我可以在单击时跟踪滚动条的当前位置,并在重新绘制表格时将值设置回?
如果它是DOM
的scroll 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了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.