簡體   English   中英

長表格滾動,但防止窗口滾動

[英]Long table scroll, but prevent window scroll

我有一張桌子,上面有很多div

<div></div>...<div></div>
<div id="tablecontent">
<table>...</table>

</div>

我希望我的表格僅在屏幕中滾動(表格底部位於窗口底部)。 所以我需要為#tablecontent設置 height 和scroll=auto 要設置高度,我將其計算為:

var pos=$("#tablecontent").position().top;
var heigth=$( window ).height()-pos;
$("#tablecontent").css("height",heigth+'px');

但這不能正常工作。 它比我需要的大。 你能幫我計算正確的值嗎?

在 CSS 中的div ,您需要設置overflow: scroll ,當內容大於容器時,固定高度應該在div上創建一個滾動條。

暫無
暫無

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

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