fade-to-view
Version:
This package fades in your elements when they are scrolled into view.
20 lines (17 loc) • 480 B
JavaScript
import './fade-to-view.css';
export default (function ftv() {
const ftv = document.querySelectorAll(".ftv");
const triggerPos = 0.9;
alert("t");
document.addEventListener("scroll", function () {
ftv.forEach(function (item) {
const top = item.getBoundingClientRect().top;
const height = window.innerHeight;
// is in view?
if (top < height * triggerPos) {
item.classList.add("ftv-show");
}
});
});
}
)();