buttons.forEach(button => { button.addEventListener(‘click’, function() { buttons.forEach(btn => btn.classList.remove(‘active’)); this.classList.add(‘active’); }); }); });
Skin Care
Body Care
Hair Care
Face Care
Baby Care
hygiene
Men Grooming
Afro Export Products
Other Popular Product
Pet Care
document.addEventListener(“DOMContentLoaded”, function() { // Select all category titles const categories = document.querySelectorAll(‘.pro_cate_title’);
// Initially open the “Room Care” category const roomCareCategory = document.querySelector(‘.pro_cate.active’); if (roomCareCategory) { roomCareCategory.querySelector(‘.pro_side_ul’).style.display = ‘block’; }
// Add click event listener to each category title categories.forEach((categoryTitle) => { categoryTitle.addEventListener(‘click’, function() { const parentCategory = categoryTitle.parentElement;
// If the clicked category is already active, return if (parentCategory.classList.contains(‘active’)) { return; }
// Close all active categories and hide their content document.querySelectorAll(‘.pro_cate’).forEach((category) => { category.classList.remove(‘active’); category.querySelector(‘.pro_side_ul’).style.display = ‘none’; });
// Open the clicked category and show its content parentCategory.classList.add(‘active’); parentCategory.querySelector(‘.pro_side_ul’).style.display = ‘block’;
// Scroll to the first item of the clicked category const firstItem = parentCategory.querySelector(‘.pro_side_ul li a’); if (firstItem) { const targetId = firstItem.getAttribute(‘href’).substring(1); // Get the target ID const targetContent = document.getElementById(targetId); // Find the target section
if (targetContent) { // Calculate the scroll position with a 150px offset const rect = targetContent.getBoundingClientRect(); const offsetTop = window.scrollY + rect.top – 150;
console.log(‘Scrolling to:’, targetId, ‘Offset top:’, offsetTop); // Debugging log
// Scroll to the target section smoothly window.scrollTo({ top: offsetTop, behavior: ‘smooth’ }); } else { console.log(‘Target content not found for ID:’, targetId); // Debugging log } } }); });
// Existing functionality: Progress bars and smooth scroll const contentItems = document.querySelectorAll(‘.pro_content_main_col .fusion-builder-row .content-item’); const sidebarItems = document.querySelectorAll(‘.pro_side_ul li a’); const progressBars = document.querySelectorAll(‘.pro_progress-bar’); let lastVisibleIndex = 0;
// Function to update the progress bars based on scroll position function updateProgressBar() { const windowHeight = window.innerHeight; const windowScrollTop = window.scrollY || window.pageYOffset;
// Loop through content items and calculate visibility contentItems.forEach((content, i) => { const rect = content.getBoundingClientRect(); const contentTop = rect.top; const contentHeight = rect.height;
if (contentTop >= 0 && contentTop < windowHeight) { const visiblePart = contentHeight – Math.max(0, contentTop); const progressWidth = (visiblePart / contentHeight) * 100; progressBars[i].style.width = `${progressWidth}%`; progressBars[i].style.display = 'block'; lastVisibleIndex = i; } else if (contentTop 0) { const progressWidth = ((contentHeight + contentTop) / contentHeight) * 100; progressBars[i].style.width = `${progressWidth}%`; progressBars[i].style.display = ‘block’; lastVisibleIndex = i; } else { progressBars[i].style.display = ‘none’; } });
// Hide progress bars for previously viewed items for (let i = 0; i < lastVisibleIndex; i++) { progressBars[i].style.display = 'none'; } }
// Throttle function to optimize the scroll event handling function throttled(delay, fn) { let lastCall = 0; return function (…args) { const now = new Date().getTime(); if (now – lastCall { sidebarItem.addEventListener(‘click’, function(e) { e.preventDefault(); const targetId = sidebarItem.getAttribute(‘href’).substring(1); // Get the target ID const targetContent = document.getElementById(targetId); // Find the target section
// Scroll to the target section smoothly window.scrollTo({ top: offsetTop, behavior: ‘smooth’ }); } else { console.log(‘Target content not found for ID:’, targetId); // Debugging log } }); }); });
Room Care
Kitchen Care
Laundry Chemical
Hygiene Care
Auto Care
Personal Care