Try to avoid Javascript, and just use CSS. For example:
<div class="outer">
<div>
<div class="left">
<p>LEFT</p>
</div>
</div>
<div>
<div class="right">
<p>RIGHT</p>
</div>
<div class="footer-wrapper">
<div class="footer">
<p>FOOTER</p>
</div>
</div>
</div>
</div>
.outer {
display: flex;
}
.outer > div:nth-child(2){
background-color: #ee4444;
display: flex;
flex-direction: column;
}
.footer-wrapper {
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
.footer {
position: sticky;
bottom: 0;
}
Demo[
^]
position - CSS: Cascading Style Sheets | MDN[
^]
CSS Flexible Box Layout - CSS: Cascading Style Sheets | MDN[
^]