Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self-scrolling html table with fixed header

I want to make an html table with fixed header and vertical scrolling body. I know this has been implemented by others however there is a twist here. The table body must scroll automatically without the need for a user to scroll using the mouse (the body scrolls from top to bottom and then back to top) similar to a split-flap airport departure board/display. I can't seem to achieve this, at the moment I'm using the marquee tag to do this, which does not look good. Below is my implementation:

<marquee behavior="scroll" direction="up" scrollamount="3" >
<table>
    <thead>
      <tr>
         <th>header1</th>
         <th>header2</th>
         <th>header3</th>
         <th>header4</th>
      </tr>
    </thead>
    <tbody>
         <tr>
            <td>cont1</td>
            <td>cont2</td>
            <td>cont3</td>
            <td>cont4</td>
         </tr>
         <tr>
            <td>cont1</td>
            <td>cont2</td>
            <td>cont3</td>
            <td>cont4</td>
         </tr>
         <tr>
            <td>cont1</td>
            <td>cont2</td>
            <td>cont3</td>
            <td>cont4</td>
         </tr>
         <tr>
            <td>cont1</td>
            <td>cont2</td>
            <td>cont3</td>
            <td>cont4</td>
         </tr>
         ...
    </tbody>
</table>

Please can someone point me the right direction on how to achieve this (using html css and jquery).

like image 432
Just Ice Avatar asked Jul 28 '26 11:07

Just Ice


2 Answers

var my_time;
$(document).ready(function() {
pageScroll();
$("#contain").mouseover(function() {
clearTimeout(my_time);
}).mouseout(function() {
pageScroll();
});
});

function pageScroll() {
var objDiv = document.getElementById("contain");
objDiv.scrollTop = objDiv.scrollTop + 1;  
if ((objDiv.scrollTop + 100) == objDiv.scrollHeight) {
objDiv.scrollTop = 0;
  }
my_time = setTimeout('pageScroll()', 25);
}

Demo

like image 171
Ranjan Avatar answered Jul 30 '26 02:07

Ranjan


Try this :

<table>
<tr>
  <td>header1</td>
 <td>header2</td>
 <td>header3</td>
 <td>header4</td>
  </tr>
</table>

 <table id="secondtbl" >        
   <tbody>
     <tr>
        <td>cont1</td>
        <td>cont2</td>
        <td>cont3</td>
        <td>cont4</td>
     </tr>
     <tr>
        <td>cont1</td>
        <td>cont2</td>
        <td>cont3</td>
        <td>cont4</td>
     </tr>
     <tr>
        <td>cont1</td>
        <td>cont2</td>
        <td>cont3</td>
        <td>cont4</td>
     </tr>
     <tr>
        <td>cont1</td>
        <td>cont2</td>
        <td>cont3</td>
        <td>cont4</td>
     </tr>
     ...
   </tbody>
</table>

CSS :

table{
 border:1px solid black;
 width:200px;
}

td{
 border:1px solid red;
 padding : 2px;
}
#secondtbl{
 width:35%;
}

This will give you the exact width of header and cell , hope it is useful

enter image description here

like image 28
Manjuboyz Avatar answered Jul 30 '26 01:07

Manjuboyz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!