feat: add fade in

This commit is contained in:
2024-12-16 15:17:41 +01:00
parent 06d2dddb1b
commit 63055bcd65
9 changed files with 67 additions and 4 deletions

View File

@@ -0,0 +1,40 @@
(function() {
document.addEventListener('DOMContentLoaded', function() {
// Elements that should fade in when in view
var fadeInElements = document.querySelectorAll('.fade-in-on-scroll');
// If IntersectionObserver is supported, use it for better performance
if ('IntersectionObserver' in window) {
var observer = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in-visible');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.1 });
fadeInElements.forEach(function(el) {
el.classList.add('fade-in-hidden');
observer.observe(el);
});
} else {
// Fallback if IntersectionObserver is not supported
fadeInElements.forEach(function(el) {
el.classList.add('fade-in-hidden');
});
var checkVisibility = function() {
var windowBottom = window.innerHeight + window.scrollY;
fadeInElements.forEach(function(el) {
if (el.getBoundingClientRect().top + window.scrollY < windowBottom - (el.offsetHeight * 0.1)) {
el.classList.add('fade-in-visible');
}
});
};
window.addEventListener('scroll', checkVisibility);
checkVisibility();
}
});
})();

View File

@@ -0,0 +1,19 @@
.fade-in-hidden {
opacity: 0;
transform: translateY(1.5rem);
transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}
.fade-in-visible {
opacity: 1;
transform: translateY(0);
}
/* Respect prefers-reduced-motion: reduce (for accessibility).
If user prefers reduced motion, override transitions. */
@media (prefers-reduced-motion: reduce) {
.fade-in-hidden {
opacity: 1;
transform: none;
transition: none;
}
}

View File

@@ -7,8 +7,10 @@
padding: 0.75rem 1.5rem;
border: none;
cursor: pointer;
transition: background 0.3s;
&:hover {
background-color: var(--bs-primary-light);
color: var(--bs-yellow);
}
}

View File

@@ -2,6 +2,7 @@
@import 'abstracts/mixins';
@import 'abstracts/fonts';
@import 'abstracts/icons';
@import 'abstracts/fade-in';
@import 'base/base';
@import 'components/navigation';
@import 'components/images';