Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, I was trying to obtain the same effect without resorting to fixed size columns or having a fixed height for the entire table.</p> <p>The solution I came up with is a hack. It consists of duplicating the entire table then hiding everything but the header, and making that have a fixed position.</p> <h3>HTML</h3> <pre><code>&lt;div id="table-container"&gt; &lt;table id="maintable"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Col1&lt;/th&gt; &lt;th&gt;Col2&lt;/th&gt; &lt;th&gt;Col3&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;some really long line here instead&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;td&gt;info&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;div id="bottom_anchor"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <h3>CSS</h3> <pre><code>body { height: 1000px; } thead{ background-color:white; } </code></pre> <h3>javascript</h3> <pre><code>function moveScroll(){ var scroll = $(window).scrollTop(); var anchor_top = $("#maintable").offset().top; var anchor_bottom = $("#bottom_anchor").offset().top; if (scroll&gt;anchor_top &amp;&amp; scroll&lt;anchor_bottom) { clone_table = $("#clone"); if(clone_table.length == 0){ clone_table = $("#maintable").clone(); clone_table.attr('id', 'clone'); clone_table.css({position:'fixed', 'pointer-events': 'none', top:0}); clone_table.width($("#maintable").width()); $("#table-container").append(clone_table); $("#clone").css({visibility:'hidden'}); $("#clone thead").css({'visibility':'visible','pointer-events':'auto'}); } } else { $("#clone").remove(); } } $(window).scroll(moveScroll); </code></pre> <p>See here: <a href="http://jsfiddle.net/QHQGF/7/" rel="noreferrer">http://jsfiddle.net/QHQGF/7/</a></p> <p>Edit: updated the code so that the thead can receive pointer events(so buttons and links in the header still work). This fixes the problem reported by luhfluh and Joe M.</p> <p>New jsfiddle here: <a href="http://jsfiddle.net/cjKEx/" rel="noreferrer">http://jsfiddle.net/cjKEx/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload