JSFiddle - React, Tailwind, and code Playground
HTML
<div class="wrap">
<div class="sidebar">
<div class="menu">Menu</div>
</div>
<div class="content">
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
</div>
<div class="footer">Footer</div>
</div>
CSS
html, body {
margin: 0;
padding: 0;
}
.sidebar {
width: 225px;
position: fixed;
top: 0;
left: 0;
bottom: 0;
overflow: auto;
padding-top: 30px;
background-color: #e9e9e9;
text-align: center;
color: white;
font-size: 3em;
}
.sidebar .menu {
width: 100%;
background-color: #999;
height: 450px;
}
.sidebar .footer {
position: absolute;
left: 0;
bottom: 0;
background-color: #75cee0;
width: 100%;
height: 100px;
}
.content {
padding-top: 30px;
margin-left: 260px;
}
.content .image {
width: 712px;
height: 400px;
margin-bottom: 30px;
background-color: #f3a450;
}
/* sidebar padding + menu height + footer height */
@media screen and (max-height: 580px) {
.sidebar .footer {
position: relative;
}
.sidebar{position: static; overflow:visible; float:left;}
}
JavaScript
$(document).scroll(function(){
if ($(window).height()<=580){
var sidebarObj=$(".sidebar");
var extraSidebar=sidebarObj.height()-$(window).height();
if ($(document).scrollTop()>extraSidebar){
if (sidebarObj.css("position")!="fixed"){
sidebarObj.css({
"position": "fixed",
"top": -extraSidebar+"px"
});
}
}
else{
sidebarObj.css({
"position": "static",
"top": 0+"px"
});
}
}
});
//reset on window resize
$(window).resize(function(){
var sidebarObj=$(".sidebar");
if ($(window).height()<=580){
sidebarObj.css({
"position": "static",
"top": 0+"px"
});
}
else{
sidebarObj.css({
"position": "fixed",
"top": 0+"px"
});
}
});