Enhance UI with animations and smooth scrolling effects

This commit is contained in:
Mohammed Al-yaseen
2025-05-14 22:31:59 +03:00
parent f42a04f156
commit 350b0b0c65
2 changed files with 251 additions and 0 deletions

View File

@@ -28,4 +28,46 @@
);
}
});
// Add navbar scroll effect
window.addEventListener('scroll', function() {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Add animation on scroll
const animateOnScroll = function() {
const elements = document.querySelectorAll('.projects-thumb, .services-thumb, .contact-info');
elements.forEach(element => {
const elementPosition = element.getBoundingClientRect().top;
const screenPosition = window.innerHeight;
if(elementPosition < screenPosition) {
element.style.opacity = '1';
element.style.transform = 'translateY(0)';
}
});
}
window.addEventListener('scroll', animateOnScroll);
window.addEventListener('load', animateOnScroll);
// Add smooth scroll for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
})(window.jQuery);