jointrashposs/assets/js/fadein/index.ts

24 lines
553 B
TypeScript
Raw Normal View History

2023-07-08 19:23:27 +02:00
export const vFadeIn = {
mounted: (src, binding, vn) => {
src.classList.add('__v_fadeIn_out');
src.children[0].style.transition = `all 0.5s ease`;
function onIntersect(entries) {
for (const entry of entries) {
if (entry.isIntersecting) {
entry.target.classList.add('__v_fadeIn_in');
} else {
entry.target.classList.remove('__v_fadeIn_in');
}
}
}
const observer = new IntersectionObserver(onIntersect, {
root: null,
rootMargin: '9999px 0px -300px 0px',
threshold: 0,
});
observer.observe(src);
}
};