JSFiddle - React, Tailwind, and code Playground
by wamosjk
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<div class="header">Header</div>
<div class="content-wrapper">
<div class="side-panel left"></div>
<div class="main-content"></div>
<div class="side-panel right"></div>
</div>
<div class="footer">Footer</div>
CSS
body, html{padding: 0;margin: 0; text-align: center; color: #fff;}
.header {background-color:#004ebc;height:150px;width:100%: margin: 0;}
.footer {background-color:#004ebc;height:550px;width:100%: margin: 0;}
.content-wrapper{
position: relative;
height: 100%;
width: 100%;
}
.main-content{
width: 60%;
height: 1000px;
position: relative;
margin: 0 auto;
background: #8a8a8a;
}
.side-panel {
position:absolute;
background-color:#532b90;
width:10%;
height:125px;
top: 0;
}
.side-panel.left{
left: 10%;
}
.side-panel.right{
right: 10%;
}
.fixed{
position: fixed;
}
.absolute-bottom{
position: absolute;
bottom: 0;
top:auto;
}
JavaScript
$(window).on( "scroll", function() {
if ( $(window).scrollTop() >= $(".content-wrapper").offset().top ) {
$( '.side-panel' ).addClass("fixed");
}else{
$( '.side-panel' ).removeClass("fixed");
}
if ( $(window).scrollTop() >= $(".footer").offset().top - $('.side-panel').height()) {
$( '.side-panel' ).addClass("absolute-bottom");
}else{
$( '.side-panel' ).removeClass("absolute-bottom");
}
});