Skip to content

Instantly share code, notes, and snippets.

@kobitoDevelopment
Last active April 8, 2022 06:49
Show Gist options
  • Save kobitoDevelopment/b972fc029fcbfae77b4ede05a0921d20 to your computer and use it in GitHub Desktop.
Save kobitoDevelopment/b972fc029fcbfae77b4ede05a0921d20 to your computer and use it in GitHub Desktop.
<p class="one">1</p>
<p class="two">2</p>
<p class="three">3</p>
const items = document.querySelectorAll("p");
items.forEach(function (elem, index) {
elem.classList.add("set");
});
$(window).on("scroll", function () {
$("p").each(function () {
if (
$(window).scrollTop() >=
$(this).offset().top - $(window).height() + 200
) {
$(this).addClass("set");
} else {
$(this).removeClass("set");
}
});
});
.one {
transition: 1s;
transition-delay: 0.5s;
opacity: 0;
&.set {
opacity: 1;
}
}
.two {
transition: 1s;
transition-delay: 1s;
opacity: 0;
&.set {
opacity: 1;
}
}
.three {
transition: 1s;
transition-delay: 1.5s;
opacity: 0;
&.set {
opacity: 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment