Хук useElementOnScreen, переключение стилей навбара

This commit is contained in:
Ifraim Solomonov committed 2024-03-01 20:58:48 +03:00
1 parent 0492530220
commit 8496cae1aa
4 files changed
+57 -5

No files matched your search

+20 -2
View File
@@ -1,11 +1,29 @@
import { useEffect } from 'react';
import { News, Projects, Labs, Partners, Gallery, ContactUs } from './components';
import useElementOnScreen from '../../lib/useElementOnScreen';
function Main() {
const [containerRef, isVisible] = useElementOnScreen({
root: null,
rootMargin: '0px',
threshold: 0,
});
useEffect(() => {
const [ navbar ] = document.getElementsByClassName('navbar');
if (isVisible) {
navbar.classList.add('absolute');
} else {
navbar.classList.remove('absolute');
}
}, [isVisible]);
return (
<>
<header className="header">
<header className="header" id="mainpageheader" ref={containerRef}>
<h1>Думай иначе, будь креативным!</h1>
<h2>Студенческое конструкторское бюро<br/>
<h2>Студенческое конструкторское бюро<br />
"Компьютерное инновационное творчество"</h2>
<a className="btn" href="">Связаться с нами</a>
</header>