admin管理员组文章数量:1325236
I want to implement infinite scrolling (with an AJAX-based loader) in an HTML table body.
My HTML looks something like this:
<table>
<thead>
<tr><th>Column</th></tr>
</thead>
<tbody>
<tr><td>Row 1</td></tr>
<tr><td>Row 2</td></tr>
</tbody>
</table>
I get a scroll bar on the <tbody>
like so:
tbody {
height:10em; /* Otherwise the tbody expands to fit all rows */
overflow:auto;
}
To be able to do anything when the user scrolls to the bottom, I need to be able to get the scroll position of the <tbody>
. In all of the (jQuery) infinite scroll implementations I've seen (such as this one), they subtract the content height from the container height and pare it to the .scrollTop() value.
Unfortunately this may not work with <tbody>
, which is both the viewport and the container for the scrolled content. $("tbody").height()
returns the viewable (ie: "shrunken") size, but I don't know how I can get the full (viewable + hidden) size of the table body. (FWIW, $("tbody").scrollTop()
returns a "large" number when scrolled to the bottom, exactly as I would expect it to).
Is there any way to acplish this?
I want to implement infinite scrolling (with an AJAX-based loader) in an HTML table body.
My HTML looks something like this:
<table>
<thead>
<tr><th>Column</th></tr>
</thead>
<tbody>
<tr><td>Row 1</td></tr>
<tr><td>Row 2</td></tr>
</tbody>
</table>
I get a scroll bar on the <tbody>
like so:
tbody {
height:10em; /* Otherwise the tbody expands to fit all rows */
overflow:auto;
}
To be able to do anything when the user scrolls to the bottom, I need to be able to get the scroll position of the <tbody>
. In all of the (jQuery) infinite scroll implementations I've seen (such as this one), they subtract the content height from the container height and pare it to the .scrollTop() value.
Unfortunately this may not work with <tbody>
, which is both the viewport and the container for the scrolled content. $("tbody").height()
returns the viewable (ie: "shrunken") size, but I don't know how I can get the full (viewable + hidden) size of the table body. (FWIW, $("tbody").scrollTop()
returns a "large" number when scrolled to the bottom, exactly as I would expect it to).
Is there any way to acplish this?
Share Improve this question asked Apr 22, 2010 at 20:05 Craig WalkerCraig Walker 51.8k58 gold badges155 silver badges212 bronze badges 1- crickets. The views keep going up but there's no activity. I'm guessing that this is simply not possible given current browsers. – Craig Walker Commented May 6, 2010 at 19:42
2 Answers
Reset to default 3tbody.scrollHeight
works for me.
When you need the hidden height you can set the height to auto, grab it, then return the height to the forced size.
var $tbody = $('tbody');
var initTbodyHeight = $tbody.height();
$tbody.css('height','auto');
var autoTbodyHeight = $tbody.height();
$tbody.css('height',initTbodyHeight);
Even IE should process this fast enough without any flicker visible to human eyes.
本文标签: javascriptScroll Position in a Table BodyStack Overflow
版权声明:本文标题:javascript - Scroll Position in a Table Body - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742164032a2425487.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论