import React, { useEffect } from 'react'; import scrollToSection from 'common/scrollToSection'; const OnePageNav = ({ navbarRef, rtl }) => { useEffect(() => { const sections = document.querySelectorAll('[data-scroll-index]'); window.addEventListener('scroll', () => { sections.forEach(section => { const index = section.getAttribute('data-scroll-index'); let offset = section.offsetTop; let height = section.offsetHeight; const scroll = window.scrollY; if (['2', '3'].indexOf(index) !== -1) { offset = section.parentElement.offsetTop + section.offsetTop - 150; } if (scroll + 200 > offset && scroll + 200 < offset + height) { document.querySelector(`[data-scroll-nav="${index}"]`)?.classList?.add('active'); } else { document.querySelector(`[data-scroll-nav="${index}"]`)?.classList?.remove('active'); } }); }); }, []); return ( ) } export default OnePageNav