JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<div class="mainSection sticky-ready">
<header>
<img src="http://placehold.it/300x80&text=Header+and+Nav" width="300" height="80" alt="header">
</header>
<section class="content clearfix">
<section class="left">
<h1 class="headlineBar"><img src="http://placehold.it/200x40/A9200D/ffffff/&text=Headlines"></h1>
<ul>
<li>
<img src="http://placehold.it/200x140/aaaaaa/ffffff&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/777777/ffffff/&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/aaaaaa/ffffff&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/777777/ffffff/&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/aaaaaa/ffffff&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/777777/ffffff/&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/aaaaaa/ffffff&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/777777/ffffff/&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/aaaaaa/ffffff&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/777777/ffffff/&text=Story+Item">
</li>
<li>
<img src="http://placehold.it/200x140/aaaaaa/ffffff&text=Story+Item">
...
CSS
/* LAYOUT */
.mainSection {
margin:0 auto;
width:350px;
}
aside {
width:100px;
float:left;
}
.left {
width:200px;
float:left;
}
.right {
float:right;
}
/* Sticky Control */
.sticky-ready .sticky {
position:fixed !important;
}
.headlineBar {
position:relative;
z-index:10;
}
/* #Reset & Basics (Inspired by E. Meyers)
================================================== */
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after, q:before, q:after {
content:'';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
JavaScript
$(function () {
var headlineBarPos = $('.headlineBar').offset().top; // returns number
var moduleControllerPos = $('.moduleController').offset().top; // returns number
var sidebarHeight = $('.sticky-sidebar-wrap').height();
var sidebarTop = $('.sticky-sidebar-wrap').offset().top;
var windowHeight = $(window).height();
var totalHeight = sidebarHeight + sidebarTop;
$(window).scroll(function () { // scroll event
var windowTop = $(window).scrollTop(); // returns number
// fixing the headline bar
if (headlineBarPos < windowTop) {
$('.headlineBar').addClass('sticky').css('top', '0');
} else {
$('.headlineBar').removeClass('sticky').removeAttr('style');
}
if (moduleControllerPos < windowTop + windowHeight) {
$('.sticky-sidebar-wrap').addClass('sticky').css('top', '0');
} else {
$('.sticky-sidebar-wrap').removeClass('sticky').removeAttr('style'); }
console.log(windowTop);
});
console.log(headlineBarPos);
console.log(sidebarHeight);
console.log(sidebarTop);
});