JSFiddle - React, Tailwind, and code Playground

by Fabio Dan

HTML

<div class="container">
  <header></header>
  <section></section>
  <section class="height-100"></section>
  <div class="grid">
    <table>
      <thead>
        <tr class="week">
          <td></td>
          <td>Today</td>
          <td>Tomorrow</td>
          <td>Wed<br>12 Jan</td>
          <td>Thu<br>13 Jan</td>
          <td>Fri<br>14 Jan</td>
          <td>Sat<br>15 Jan</td>
          <td>Sun<br>16 Jan</td>
          <td>Mon<br>17 Jan</td>
          <td>Tue<br>18 Jan</td>
          <td>Wed<br>19 Jan</td>
          <td>Thu<br>20 Jan</td>
          <td>Fri<br>21 Jan</td>
          <td>Sat<br>22 Jan</td>
          <td>Sun<br>23 Jan</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td id="firstRow" class="time">6:00 to 7:00am</td>
          <td><div class="cell">£4.50&nbsp;*</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
        </tr>
        <tr>
          <td class="time">7:00 to 8:00am</td>
          <td><div class="cell">£4.50&nbsp;*</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
          <td><div class="cell">£4.50</div></td>
         ...

CSS

html {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  -webkit-box-sizing: inherit;
  -moz-box-sizing: inherit;
  box-sizing: inherit;
}

body {
  margin: 0;
  font-family: "Helvetica Neue";
  font-size: 1em;
}

.container {
  background: white;
  /* width: 320px; */
  height: 564px;
}

header {
  background: #EEE;
  height: 70px;
  margin: 0 0 24px 0;
}

section {
  background: #EEE;
  height: 170px;
  margin: 0 16px 16px 16px;  
}

.height-100 {
  height: 100px;
}

.grid {
  position: relative;
  overflow-x: scroll;
  overflow-y: hidden;
  border: solid 1px #CCC;  
  border-style: solid none;
}

table {
  border-collapse: collapse;  
}
td {
  margin: 0;
}
table td {
  width: 150px;
  text-align: center;
  padding: 8px 16px;
  height: 64px;
  color: #3D3D3D;
}

thead td {
  position: sticky;
  top: 0;
  left: auto;
  background: white;
  height: 64px;
  z-index: 100;
  font-size: 13px;
  color: #767676;
}

thead td::after {
  content: "";
  display: block;
  width: 100%;
  height: 1px;
  background: #CCC;
  position: absolute;
  bottom: 0;
  left: 0; 
}

.time {
  position: sticky;
  top: auto;
  left: 0;
  background: white;
  z-index: 0;
  color: #767676;
  font-size: 13px;
  padding: 8px;
}

.time::after {
  content: "";
  display: block;
  width: 1px;
  height: 100%;
  background: #CCC;
  position: absolute;
  right: 0;
  top: 0; 
}

footer {
  border: solid 1px #CCC;
  border-style: solid none;
  background: white;
  padding: 16px;
  position: absolute;
  top: 160px;
  left: 0;
  right: 0;
  font-size: 13px;
  color: #767676;
  width: 100%;
}

.grid--scroll footer {
  position: fixed;
  bottom: 0;
  left: 0;
  top: auto;
}

.grid--end footer {
  position: static;
  bottom: auto;
  left: auto;
  top: auto;
}

JavaScript

const toggleScroll = () => {
	const footer = document.querySelector("footer");
	const firstRow = document.getElementById("firstRow")
	const position = firstRow.getBoundingClientRect();
	const grid = document.querySelector(".grid");

	// checking whether fully visible
	if(position.bottom + 32 + footer.offsetHeight <= window.innerHeight) {
	  grid.classList.add("grid--scroll")
		console.log('Element is fully visible in screen');
	} else {
	  grid.classList.remove("grid--scroll")
		console.log('Element is NOT fully visible in screen');  	
  }
}

window.addEventListener('scroll', toggleScroll);
window.addEventListener('DOMContentLoaded', toggleScroll);