有没有 css3 方法来修复?在y轴上,让它在x轴上滚动?
这个问题已经被问过无数次了:这里,<一个href="https://stackoverflow.com/questions/4334205/how-can-i-tell-iscroll-that-a-tbody-should-scroll-and-vanish-behind-a-thead"> 那里、 和 另一个地方就在所以。然而我找不到真正好的答案。
<回顾>通常我的表格在垂直方向上比视口深得多。我希望能够滚动表格的 ,同时其
保持固定且可见。其中一些表格也比视口宽得多。在这里,我希望表格的
水平滚动。
为了达到效果,我有几十行JS,包括setInterval()
调用来检查scrollLeft
和scrollTop
,以便我可以重新定位1 的副本。它确实有效,但它是一个巨大的、笨拙的、脆弱的、难以维持的痛苦。
问题:是否有一些简单的 css3 方式(现有的、新兴的或提议的),我可以用它来获取表的 和
< /code> 水平和垂直滚动,但彼此独立? 谢谢!
1 为什么setInterval( )
?因为 IE 不统一传递 onScroll
事件,你傻了; 每个人都知道这一点!
This has been asked a zillion times: here, there, and the other place just on SO. Yet there's no real good answer that I can find.
<recap> Often I have tables that are vertically much deeper than the viewport. I'd like to be able to scroll the table's <tbody>
while its <thead>
remains fixed and visible. Some of these tables are also much wider than the viewport. Here I want the table's <thead>
to scroll horizontally.
To get the effect, I have dozens of lines of JS, including setInterval( )
calls to check scrollLeft
and scrollTop
, so that I can reposition a copy of <thead>
1. It works but it's a huge, ungainly, frail and unmaintainable pain in the ass.</recap>
Question: Is there some straightforward css3 way, existent or emerging or proposed, that I can use to get a a table's <thead>
and <tbody>
to scroll horizontally and vertically, yet independently of each other?
Thanks!
1 Why setInterval( )
? Because IE doesn't uniformly deliver onScroll
events, you silly; everybody knows that!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终根据@Naveed Ahmad 的建议对“解决方案”进行了建模。我将表的数据部分放在 中;并做了一个假的<头>我在 onLoad 时通过参考第一个表行中的 的宽度和偏移量填写,如下所示:
这或多或少可行 在此页面上。
I ended up modeling the "solution" on the suggestion of @Naveed Ahmad. I put the data part of the table in a <tbody>; and made a fake <thead> that I filled in at onLoad time by referring to the widths and offsets of the <td>s in the first table row, like this:
This works more or less OK on this page.
一种肮脏的方法是将标题表放在单独的 div 中,例如:
然后将正文放在另一个 div 中,例如:
现在您可以为 body
div
提供固定高度并设置oveflow
到自动
。就像:这是我在 jsfiddle 中所做的一个工作示例
a dirty way would be to put the header table in a separate div like:
Then body in the another div like:
Now you can give a fixed height to body
div
and setoveflow
toauto
. like:here is a working example I did in jsfiddle