elitefit-haven / script.js
ctf2's picture
Website for high end fitness cub concept
d2959e4 verified
raw
history blame contribute delete
986 Bytes
document.addEventListener('DOMContentLoaded', function() {
// Smooth scrolling 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 classes on scroll
const animateOnScroll = function() {
const elements = document.querySelectorAll('.animate-on-scroll');
elements.forEach(element => {
const elementPosition = element.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (elementPosition < windowHeight - 100) {
element.classList.add('animate-fade-in');
}
});
};
window.addEventListener('scroll', animateOnScroll);
animateOnScroll(); // Run once on load
});