JSFiddle - React, Tailwind, and code Playground
by funkwurm
HTML
<div id="body">
<div id="sectionA" class="div">First section</div>
<div id="sectionB" class="div">Second section</div>
<div id="sectionC" class="div">Third section
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div id="footer" class="div cf">Footer</div>
</div>
CSS
* {
margin: 0;
padding: 0
}
body {
background-color: #800000
}
/* clear fix */
cf:after {
visibility:hidden;
display:block;
content:"";
clear:both;
height:0
}
* html .cf {
zoom:1
}
/* IE6 */
*:first-child+html .cf {
zoom:1
}
/* IE7 */
.div {
height: 500px;
width: 100%;
display: block;
position: relative;
}
#sectionA {
background-color: #ABFF8F;
}
#sectionB {
background-color: #FFDF80;
}
#sectionC {
background-color: #A8E9FF;
height: 100px !important;
z-index: 1;
}
#footer {
background-color: #666;
color: #fff;
font-weight: bold;
font-size: 2em;
z-index: 10;
top:0;
}
.box {
width:50px;
margin: 0 20px 20px 0;
height: 50px;
display: block;
background-color: #f2f2f2;
float: left;
}
JavaScript
var $window = jQuery(window),
$footer = jQuery("#footer"),
$viewport = window.innerHeight,
$startEffect = $footer.offset().top - $viewport;
function footerParallax() {
var $scrollPos = $window.scrollTop() - $startEffect,
$ratio = 0.6,
$newTop = -($scrollPos * $ratio),
$oldTop = parseInt($footer.css('top')),
$nonRelTop = $footer.offset().top - $oldTop,
$wanted = ($window.scrollTop()+$viewport-$footer.height());
if ($nonRelTop + $newTop < $wanted) {
$('#sectionC').css('display', 'none');
$wanted = ($window.scrollTop()+$viewport-$footer.height());
$nonRelTop = $footer.offset().top - $oldTop;
$newTop = $wanted - $nonRelTop;
} else {
$('#sectionC').css('display', 'block');
}
$footer.css('top', $newTop);
}
$window.scroll(footerParallax);