JSFiddle - React, Tailwind, and code Playground
by masteram
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;
}
.abs{
position:absolute;
}
#body{
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;
}
.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;
$body = jQuery('#body').append($('<div/>',{height: 0.4*$footer.height()}));
$footer.addClass('abs');
function footerParallax() {
var $scrollPos = $window.scrollTop() - $startEffect,
$ratio = 0.6;
console.log($scrollPos);
if(scrollPos > 0){
$footer.css({
bottom: -($scrollPos * $ratio)
});
}
}
$window.scroll(function () {
footerParallax();
});