var headerInitOpacity = '0.3';
var headerStickyOpacity = '0.9';
var headerInitHeight = '80px';
var headerStickyHeight = '70px';
var headerHidingPoint = 40; // Scrolling point that triggers hiding the header (px)
var prevScrollpos = window.pageYOffset;
function handleScroll() {
var currentScrollPos = window.pageYOffset;
var navbar = document.getElementById("navbar");
// Determine the desired state of the navbar based on the current scroll position
var desiredState = getDesiredNavbarState(currentScrollPos, navbar.style.top);
if (desiredState.needsUpdate) {
// Temporarily remove the event listener to prevent multiple triggers
window.removeEventListener('scroll', handleScroll);
// Apply the desired navbar state
navbar.style.top = desiredState.top;
navbar.style.background = desiredState.background;
navbar.style.minHeight = desiredState.minHeight;
console.log(desiredState.logMessage); // Logging the action taken
// Re-add the event listener after a delay
setTimeout(function() {
window.addEventListener('scroll', handleScroll);
}, 50); // 100ms delay
}
prevScrollpos = currentScrollPos;
}
function getDesiredNavbarState(currentScrollPos, currentTop) {
if (prevScrollpos > currentScrollPos && currentScrollPos > headerHidingPoint) {
if (currentTop != "0px") {
return { needsUpdate: true, top: "0", background: "rgba(255, 255, 255, " + headerStickyOpacity + ")", minHeight: headerStickyHeight, logMessage: 'Sticking header' };
}
} else if (currentScrollPos <= headerHidingPoint) {
if (currentTop == "0px") {
return { needsUpdate: true, top: "0", background: "rgba(255, 255, 255, " + headerInitOpacity + ")", minHeight: headerInitHeight, logMessage: 'Top header' };
}
} else if (currentTop != "-100px") {
return { needsUpdate: true, top: "-100px", background: "", minHeight: "", logMessage: 'Hiding header' };
}
return { needsUpdate: false }; // No update needed
}
// Initially attach the scroll event listener
window.addEventListener('scroll', handleScroll);
Blog – All Topic
Menu
All Topics
Turn to XOA TAX News for all the latest news, insights and stories of our tax expertise and care.
Business Tax
Navigate the world of business taxes with ease. We break down tax planning, deductions, and filing processes into simple steps, helping you handle your taxes easily.
Tackle your taxes with confidence. Our straightforward advice on tax credits, deductions, and filing makes tax season less daunting and more rewarding for you.
Dive into easy-to-follow guides on managing your business finances. From budgeting to profit analysis, we make accounting simple and practical for you.
Learn how to keep track of money in different projects. We show you simple ways to manage your costs and profits, making sure your construction work pays off.
Learn the secrets of successful financial planning in construction. We introduce you to strategies and techniques that ensure your projects are both efficient and profitable.
Learn the essentials of payroll management. We cover everything from calculating wages to handling tax deductions, ensuring you pay your team correctly and confidently.
Discover stress-free methods to track your daily business transactions. Our tips help you keep your financial records neat and understandable, saving you time and worry.
Learn practical ways to manage your e-commerce finances, from streamlining costs to maximizing profits, ensuring your online business soars to #Success.
Explore effective ways to manage your business day-to-day. From improving customer service to streamlining operations, our expert advice is delivered to help your business run smoothly.
Keep up with the latest business and financial trends without the jargon. Our news updates are easy to understand, keeping you informed and ready in the VUCA world.