确定 html 表格中的顶行
我有一个带有滚动条的 html 表(即设置了溢出)。当我滚动表格时,我想获取当前顶行的位置(即根据表格的用户视图)。
我该怎么做?
你们中有人能帮我举个例子吗?
I have a html table with scrollbar (i.e. overflow is set). When I scroll the table, I would like to get the the current top-row in position (i.e. according to user-view of table).
How would I do this?
Can anyone of you help me with an example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用普通 JavaScript,以下内容可能会帮助您入门。它绝对不完美,但可能会激发一些想法... JSFiddle 示例
< Strong>[更新] 来自上面
JavaScript
HTML
CSS链接的代码
Here is something that might help get you started if you're going at it with vanilla JavaScript. It's definitely not perfect but might spark some ideas... JSFiddle Example
[update] code from link above
JavaScript
HTML
CSS
如果你不想使用 JQuery 你可以这样做。
If you don't want to use JQuery you can do it this way.
这是一些模拟代码。它将最上面的[相对于用户的观点]表行的背景颜色设置为#FF00FF。尚未使用嵌套表对此进行测试。它也可能会获取表内的表行...因此,在测试 TR 之前,您必须检查 TR 的父节点。
Heres some mock up code.. It sets the topmost [relative to the user's point of view] table row's background color to #FF00FF. Haven't tested this with nested tables. It'll probably pick up the rows of tables inside your table as well... So you'd have to check the parentNode of your TRs before testing them.