表:修复了使用JS滚动时的ad

Table: Fixed thead during scroll with JS

本文关键字:滚动 JS ad      更新时间:2023-09-26

当您滚动该表时,我正在尝试修复该表上的thead,但没有任何结果。

这是我尝试过的JS:

<script>
   document.getElementById("tablepress-10").addEventListener("scroll", function() {
      var translate = "translate(0," + this.scrollTop + "px)";
      this.querySelector("thead").style.transform = translate;
   });
</script>

有什么建议吗?

这可以在大量浏览器上通过HTML/CSS实现。

这里有一个很好的解决方案汇总,适用于具有固定标题的表,主要是CSS:Scrolling HTML Table with fixed Header

最简单的方法是使用插件。我知道这是一个使用jQuery的http://laertejjunior.github.io/freezeheader/#demo