remove reliance on intersection observer

This commit is contained in:
keyan 2024-04-04 15:37:51 -05:00
parent a785f907cb
commit 2bf11dc848
2 changed files with 40 additions and 38 deletions

View File

@ -6,6 +6,7 @@
background-color: var(--bs-body-bg); background-color: var(--bs-body-bg);
border-top: 1px solid var(--theme-toolbarActive); border-top: 1px solid var(--theme-toolbarActive);
z-index: 1000; z-index: 1000;
justify-content: end;
} }
.footerPadding { .footerPadding {

View File

@ -7,24 +7,26 @@ import classNames from 'classnames'
export default function StickyBar ({ prefix, sub, path, topNavKey, dropNavKey }) { export default function StickyBar ({ prefix, sub, path, topNavKey, dropNavKey }) {
const ref = useRef() const ref = useRef()
const sticky = useRef()
const me = useMe() const me = useMe()
useEffect(() => { useEffect(() => {
const observer = new window.IntersectionObserver(([entry]) => { const stick = () => {
sticky?.current?.classList.toggle(styles.hide, entry.isIntersecting) if (window.scrollY > 100) {
}) ref.current?.classList.remove(styles.hide)
ref?.current && observer.observe(ref.current) } else {
ref.current?.classList.add(styles.hide)
}
}
window.addEventListener('scroll', stick)
return () => { return () => {
ref?.current && observer.unobserve(ref.current) window.removeEventListener('scroll', stick)
} }
}, [ref?.current, sticky?.current]) }, [ref?.current])
return ( return (
<> <div className={classNames(styles.hide, styles.sticky)} ref={ref}>
<div ref={ref} style={{ position: 'relative', top: '50px' }} />
<div className={classNames(styles.hide, styles.sticky)} ref={sticky}>
<Container className='px-0 d-none d-md-block'> <Container className='px-0 d-none d-md-block'>
<Navbar className='py-0'> <Navbar className='py-0'>
<Nav <Nav
@ -52,6 +54,5 @@ export default function StickyBar ({ prefix, sub, path, topNavKey, dropNavKey })
</Navbar> </Navbar>
</Container> </Container>
</div> </div>
</>
) )
} }