Enhance UI with animations and smooth scrolling effects
This commit is contained in:
42
js/custom.js
42
js/custom.js
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user