// i is id, t is distance from top, d is depth (1-100)
// depth of 50 will scroll at normal scroll speed.
plax = [{
"i": "sue",
"t": 50,
"d": 90
},
{
"i": "mark",
"t": 100,
"d": 50
},
{
"i": "janis",
"t": 500,
"d": 50
},
{
"i": "donna",
"t": 300,
"d": 1
}
];
$window = $(window);
$(function() {
$.each(plax, function() {
eyedee = "#" + this['i'];
$(eyedee).addClass("plax");
m = mathIt(this['d'], this['t']);
$(eyedee).css({
"top": m,
"z-index": -this['d']
});
});
$window.scroll(function() {
$.each(plax, function() {
eyedee = "#" + this['i'];
m = mathIt(this['d'], this['t']);
$(eyedee).css("top", m);
});
});
});
function mathIt(d, t) {
return ((((d - 50) * 2) / 100) * $(window).scrollTop()) + t;
}
.plax {
position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="sue">here's sue</div>
<div id="mark">
<h2>here's mark</h2>
</div>
<div id="donna">
<h1>here's donna</h1>
</div>
<div id="janis">
<h2>here's janis</h2>
</div>