eduvaud-explorer / script.js
froublot's picture
donne moii 2 pages une pages qui affiche toutes les formations et une autres page qui presente une formation, seulement c'est 2 pages pas autres choses {
4cd558e verified
Raw
History Blame Contribute Delete
1.55 kB
// Shared functions and utilities
// Debounce function for resize events
function debounce(func, wait = 100) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => {
func.apply(this, args);
}, wait);
};
}
// Check if element is in viewport
function isInViewport(element) {
const rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
// Add smooth scrolling to all links
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
});
// Handle back to top button
window.addEventListener('scroll', debounce(() => {
const backToTop = document.getElementById('back-to-top');
if (backToTop) {
if (window.pageYOffset > 300) {
backToTop.classList.remove('opacity-0', 'invisible');
backToTop.classList.add('opacity-100', 'visible');
} else {
backToTop.classList.remove('opacity-100', 'visible');
backToTop.classList.add('opacity-0', 'invisible');
}
}
}));