In header.html:
Added IDs to navigation links Added script to hide expertise and contact links on non-index pages Kept the Start link visible on all pages to return to homepage In components.js: Fixed the COMPONENTS_LOADED_EVENT declaration to prevent duplicate declaration error Added condition to only enable scroll behavior on index page Kept component loading logic but made it more robust
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Custom event for when components are fully loaded
|
||||
const COMPONENTS_LOADED_EVENT = 'componentsLoaded';
|
||||
const COMPONENTS_LOADED_EVENT = new Event('componentsLoaded');
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Helper function to handle component loading
|
||||
@@ -28,7 +28,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
]).then(results => {
|
||||
if (results.every(Boolean)) {
|
||||
// Dispatch custom event when all components are loaded
|
||||
document.dispatchEvent(new CustomEvent(COMPONENTS_LOADED_EVENT));
|
||||
document.dispatchEvent(COMPONENTS_LOADED_EVENT);
|
||||
}
|
||||
}).catch(error => {
|
||||
console.warn('Error loading components:', error);
|
||||
@@ -68,33 +68,35 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
});
|
||||
}
|
||||
|
||||
// Scroll behavior
|
||||
let lastScrollTop = 0;
|
||||
let scrollTimeout;
|
||||
// Scroll behavior - only enable on index page
|
||||
if (window.location.pathname === '/' || window.location.pathname === '/index.html') {
|
||||
let lastScrollTop = 0;
|
||||
let scrollTimeout;
|
||||
|
||||
window.addEventListener('scroll', () => {
|
||||
if (scrollTimeout) {
|
||||
window.cancelAnimationFrame(scrollTimeout);
|
||||
}
|
||||
window.addEventListener('scroll', () => {
|
||||
if (scrollTimeout) {
|
||||
window.cancelAnimationFrame(scrollTimeout);
|
||||
}
|
||||
|
||||
scrollTimeout = window.requestAnimationFrame(() => {
|
||||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||||
|
||||
// Don't hide header when near top of page
|
||||
if (scrollTop < 100) {
|
||||
header.style.transform = 'translateY(0)';
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide header on scroll down, show on scroll up
|
||||
if (scrollTop > lastScrollTop) {
|
||||
header.style.transform = 'translateY(-100%)';
|
||||
} else {
|
||||
header.style.transform = 'translateY(0)';
|
||||
}
|
||||
|
||||
lastScrollTop = scrollTop;
|
||||
});
|
||||
}, { passive: true });
|
||||
scrollTimeout = window.requestAnimationFrame(() => {
|
||||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||||
|
||||
// Don't hide header when near top of page
|
||||
if (scrollTop < 100) {
|
||||
header.style.transform = 'translateY(0)';
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide header on scroll down, show on scroll up
|
||||
if (scrollTop > lastScrollTop) {
|
||||
header.style.transform = 'translateY(-100%)';
|
||||
} else {
|
||||
header.style.transform = 'translateY(0)';
|
||||
}
|
||||
|
||||
lastScrollTop = scrollTop;
|
||||
});
|
||||
}, { passive: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user