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 class="time">6:00 to 7:00am</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>
<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 *</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...
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 {
/* height: 400px; */
position: relative;
overflow-x: scroll;
overflow-y: hidden;
}
.grid--scroll {
overflow-y: scroll;
}
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;
background: white;
padding: 16px;
position: sticky;
bottom: 0;
left: 0;
font-size: 13px;
color: #767676;
width: 100%;
}
.footer--fixed {
position: fixed;
bottom: 0;
}
JavaScript
const toggleScroll = () => {
var element = document.querySelector('.grid');
var position = element.getBoundingClientRect();
// checking whether fully visible
if(position.bottom - 4 <= window.innerHeight) {
element.classList.add("grid--scroll")
console.log('Element is fully visible in screen');
} else {
element.classList.remove("grid--scroll")
console.log('Element is NOT fully visible in screen');
}
}
window.addEventListener('scroll', toggleScroll);
window.addEventListener('DOMContentLoaded', toggleScroll);