jointrashposs/assets/js/fadein/index.ts
2023-07-09 02:23:27 +09:00

24 lines
553 B
TypeScript

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);
}
};