JSFiddle - React, Tailwind, and code Playground
by Puddster
HTML
<div class="contentDiv"> </div>
<div class="bigDiv" style="background-color: red">One</div>
<div class="bigDiv" style="background-color: blue">Two</div>
<div class="bigDiv" style="background-color: green">Three</div>
<div class="bigDiv" style="background-color: yellow">Four</div>
<div class="bigDiv" style="background-color: navy">Five</div>
<div class="bigDiv" style="background-color: lime">Six</div>
<div class="bigDiv" style="background-color: DimGray">Seven</div>
<div class="bigDiv" style="background-color: gold">Eight</div>
<div class="bigDiv" style="background-color: ivory">Nine</div>
<div class="bigDiv" style="background-color: chocolate">Ten</div>
<div id="pos" style="position: fixed; bottom: 15px; right: 15px;"></div>
CSS
.bigDiv {
height: 100%;
width: 100%;
position: fixed;
top: 0px;
left: 0px;
font-size: 10em;
font-weight: 900;
text-align: center;
}
JavaScript
var curScroll = $("html").scrollTop(),
divCount = $(".bigDiv").length;
$(document).ready(function () {
$(".contentDiv").css("min-height", $(window).height() * 2);
$(".bigDiv").slice(-(divCount - 1)).hide();
$(window).scroll(function () {
if ($(window).scrollTop() > curScroll) {
if ($(".bigDiv").filter(":visible").last().next().hasClass("bigDiv")) {
$(".bigDiv").finish(false, true).slideUp().filter(":visible").last().next().slideDown();
}
$("#pos").text("Down to: " + $(window).scrollTop() + "px");
} else {
if ($(".bigDiv").filter(":visible").first().prev().hasClass("bigDiv")) {
$(".bigDiv").finish(false, true).slideUp().filter(":visible").first().prev().slideDown();
}
$("#pos").text("Up to: " + $(window).scrollTop() + "px");
}
curScroll = $(window).scrollTop();
});
});