簡體   English   中英

跟蹤 HTML div 內的滾動位置

[英]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將始終位於表格的頂部。 無論如何我可以在單擊時跟蹤滾動條的當前位置,並在重新繪制表格時將值設置回?

如果它是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了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM