davidovicnikola's picture
<!doctype html>
90785ec verified
Raw History Blame Contribute Delete
1.07 kB
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Add animation class to elements as they come into view
const animateOnScroll = () => {
const elements = document.querySelectorAll('.fade-in');
elements.forEach(element => {
const elementPosition = element.getBoundingClientRect().top;
const screenPosition = window.innerHeight / 1.3;
if (elementPosition < screenPosition) {
element.classList.add('animate-fadeIn');
}
});
};
window.addEventListener('scroll', animateOnScroll);
window.addEventListener('load', animateOnScroll);
// Mobile menu toggle functionality (will be used by navbar component)
window.toggleMobileMenu = function() {
const menu = document.getElementById('mobile-menu');
menu.classList.toggle('hidden');
};